You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we want to publish SenseHat sensors state on several topics, this could help
# import mock# sense = mock.Mock() # Mock SenseHat for testingfromcollectionsimportOrderedDict# Define a dictionary for sensors# key: sensor name# value: a "callable" to get value of a sensord_sensors=OrderedDict([
('pixels', sense.get_pixels),
('humidity', sense.get_humidity),
('temperature', sense.get_temperature_from_humidity),
('temperature_from_pressure', sense.get_temperature_from_pressure),
('pressure', sense.get_pressure),
('orientation', sense.get_orientation),
('compass', sense.get_compass),
('gyroscope', sense.get_gyroscope),
('accelerometer', sense.get_accelerometer),
])
sensors=d_sensors.keys() # all sensors#sensors = ['temperature', 'pressure']forsensorinsensors:
get_value=d_sensors[sensor] # get a "callable"print(sensor, get_value)
data= {
'ts': now.isoformat(),
'd': {
sensor: get_value()
}
}
payload=json.dumps(data) # serializationcli.publish(topic='/sensors/SenseHat01/%s'%sensor, payload=payload, qos=0, retain=False)
...
We can (should?) also consider that we have only one topic per SenseHat and all sensors state are publish on the same topic so data (d) should be create accordingly.
MQTT sample should be add in this repository.
subscriber should be able to display data in console or plot matplotlib graph or pyqtgraph.
see https://github.com/scls19fr/numpy-buffer/tree/master/samples
vispy may also be considered http://vispy.org/
If we want to publish SenseHat sensors state on several topics, this could help
We can (should?) also consider that we have only one topic per SenseHat and all sensors state are publish on the same topic so data (
d
) should be create accordingly.The text was updated successfully, but these errors were encountered: