Вещи на python - Сергей Матвеенко, dataart
TRANSCRIPT
AllJoyn Protocol
● Open source● Operating system independence● Language independence● Physical network and protocol independence● Dynamic configuration● Service advertisement and discovery● Security● Object model and remote method invocation● Software componentry
● AllSeen Alliance https://allseenalliance.org/● DataArt http://orange.dataart.com/tag/iot/
Connect
def device_discovered(mac, name, rssi):
ble_connect(mac)
class Lamp:
# ...
def connect(self):
self.status = 'CONNECTED'
self._dbus = LampService(self.mac)
self._config = ConfigService(self.mac, "DeviceHiveVB")
self._controlpanel = ControlPanelService(self.mac)
ble.connect_to_signal("DeviceDiscovered", device_discovered)
ble_connect(self.mac)
Calling alljoyn bridge
bridge = dbus.Interface(
bus.get_object(DBUS_BRIDGE_NAME, DBUS_BRIDGE_PATH),
dbus_interface='com.devicehive.alljoyn.bridge')
bridge.AddService(
self._dbus.m_service_path, self._dbus.m_service_name,
ALLJOYN_LIGHT_PATH, ALLJOYN_LIGHT_NAME, INTROSPECT)
bridge.AddService(
self._config.m_service_path, self._config.m_service_name,
ALLJOYN_CONFIG_PATH, ALLJOYN_CONFIG_NAME, CONFIG_INTROSPECT)
bridge.StartAllJoyn(self._dbus.m_service_name)
Turn It On(Off)
def turnOnOff(self, state):
self.OnOff = state
if state:
print("***LAMP NOW IS ON***")
ble.GattWrite(
self.mac, SATECHI_COLOR_CHAR, '0f0d0300ffffffc800c800c8000059ffff')
else:
print("***LAMP NOW IS OFF***")
ble.GattWrite(
self.mac, SATECHI_COLOR_CHAR, '0f0d0300ffffff0000c800c8000091ffff')
Run
def worker():
time.sleep(2)
mac = 'd05fb831379f'
Lamp(mac, 'Virtual Lamp').connect()
# init d-bus
GObject.threads_init()
dbus.mainloop.glib.threads_init()
# start mainloop
loop = GObject.MainLoop()
worker_thread = threading.Thread(target=worker,)
worker_thread.start()
loop.run()
What’s next?
● Try it and give feedback● Build something smart● Contribute!
○ Code :)○ Docs○ Use cases○ Compatibility info
?...
● https://github.com/devicehive
● http://orange.dataart.com/tag/iot/
● http://spbpython.guru
-- Serge MatveenkoDataArt