-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor mqtt service status #87
Merged
Merged
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
17316d9
feat: alarm status link to device
mxmaxime 70927af
refactor: mqtt status manage thread topics
mxmaxime 730241c
wip refactor: camera status & mqtt connection topic
mxmaxime e508f2f
refactor: mqtt sound/speaker topics
mxmaxime 493ac7e
feat(mqtt json): try/catch if json decode raise decode error
mxmaxime 02237ca
feat: get device_id from mqtt topic
mxmaxime 0a200bb
feat: stop the speaker when nobody
mxmaxime 009cf05
refactor: mqtt status publish via a new specialized class
mxmaxime 916ffe2
clean: remove payload from mqtt message
mxmaxime 991066c
feat: working on boolean payload + config clean_session
mxmaxime 14efd4e
feat: subscribe to utf8 payload topic
mxmaxime ea6f5d0
wip: camera merge topic
mxmaxime 8a08ddf
fix#92 apply brg to rbg transform opencv capture
mxmaxime d66ada0
feat: camera status retain
mxmaxime f3a7072
feat: thread manager clean for boolean
mxmaxime cc072fc
feat: messaging send status as real boolean
mxmaxime 46188e7
fix: tiredness
mxmaxime 048af8b
clean
mxmaxime 11df32b
refactor: extract things to files
mxmaxime f1734aa
todo: ref issue
mxmaxime 5cd950b
fix: wrong extend
mxmaxime 5380b58
refactor: extract django init for standalone scripts to function
mxmaxime 0ff75bf
feat: improve mqtt callback logging
mxmaxime 6bfc97a
fix: things
mxmaxime ef510f6
fix: when client_id is none clean_session has to be True
mxmaxime 04f4561
feat: log when up/off smart camera
mxmaxime f0a253f
clean
mxmaxime 11e61c7
fix: camera initialization
mxmaxime 64475f5
clean
mxmaxime 5689739
improve: send boolean as bytes and not str for connected topic
mxmaxime c238995
clean: old print
mxmaxime e88dc43
feat: detect when we lost mqtt connection with a device service
mxmaxime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import struct | ||
|
||
|
||
class MqttStatus(): | ||
mxmaxime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def __init__(self, mqtt_client): | ||
self._mqtt_client = mqtt_client | ||
|
||
def publish(self, topic, message: bool): | ||
status_bytes = struct.pack('?', message) | ||
print(f'send status: {status_bytes} on {topic}') | ||
self._mqtt_client.publish(topic, status_bytes, qos=1, retain=True) | ||
|
||
|
||
class SpeakerMessaging(): | ||
def __init__(self, mqtt_status: MqttStatus): | ||
self._mqtt_status = mqtt_status | ||
|
||
def publish_speaker_status(self, device_id: str, status: bool): | ||
self._mqtt_status.publish(f'status/speaker/{device_id}', status) | ||
|
||
|
||
class AlarmMessaging(): | ||
|
||
def __init__(self, mqtt_status: MqttStatus, speaker_messaging: SpeakerMessaging): | ||
self._mqtt_status = mqtt_status | ||
self._speaker_messaging = speaker_messaging | ||
|
||
def publish_alarm_status(self, device_id: str, status: bool): | ||
self._mqtt_status.publish(f'status/camera/{device_id}', status) | ||
|
||
if status is False: | ||
self._speaker_messaging.publish_speaker_status(device_id, False) | ||
|
||
|
||
def speaker_messaging_factory(mqtt_client): | ||
mqtt_status = MqttStatus(mqtt_client) | ||
|
||
return SpeakerMessaging(mqtt_status) | ||
|
||
|
||
def alarm_messaging_factory(mqtt_client): | ||
mqtt_status = MqttStatus(mqtt_client) | ||
speaker = speaker_messaging_factory(mqtt_client) | ||
|
||
return AlarmMessaging(mqtt_status, speaker) |
21 changes: 21 additions & 0 deletions
21
raspberrypi_central/webapp/app/alarm/migrations/0007_alarmstatus_device.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 3.0.7 on 2020-09-14 15:36 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('devices', '0002_auto_20200731_2128'), | ||
('alarm', '0006_auto_20200809_1008'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='alarmstatus', | ||
name='device', | ||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='devices.Device'), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have changed the way status are working so we need to tell the system if nobody is here when the camera is starting up. So basically, if in the first frame we don't detect anybody, we have to publish a message to inform the system.