Top Banner
“Things” in Python Serge Matveenko DataArt
12

Вещи на Python - Сергей Матвеенко, DataArt

Apr 15, 2017

Download

Technology

it-people
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Вещи на Python - Сергей Матвеенко, DataArt

“Things” in PythonSerge Matveenko

DataArt

Page 2: Вещи на Python - Сергей Матвеенко, DataArt
Page 3: Вещи на Python - Сергей Матвеенко, DataArt
Page 4: Вещи на Python - Сергей Матвеенко, DataArt

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/

Page 5: Вещи на Python - Сергей Матвеенко, DataArt

DeviceHive

github.com/devicehive

Page 6: Вещи на Python - Сергей Матвеенко, DataArt

DeviceHive Framework

github.com/devicehive/IoT-framework

Page 7: Вещи на Python - Сергей Матвеенко, DataArt

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)

Page 8: Вещи на Python - Сергей Матвеенко, DataArt

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)

Page 9: Вещи на Python - Сергей Матвеенко, DataArt

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')

Page 10: Вещи на Python - Сергей Матвеенко, DataArt

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()

Page 11: Вещи на Python - Сергей Матвеенко, DataArt

What’s next?

● Try it and give feedback● Build something smart● Contribute!

○ Code :)○ Docs○ Use cases○ Compatibility info

Page 12: Вещи на Python - Сергей Матвеенко, DataArt

?...

● https://github.com/devicehive

● http://orange.dataart.com/tag/iot/

● http://spbpython.guru

-- Serge MatveenkoDataArt