This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
allthingstalk [2018/11/13 17:30] dan.tudose [Trimiterea de comenzi] |
allthingstalk [2018/11/16 10:07] (current) dan.tudose [Trimiterea de date] |
||
|---|---|---|---|
| Line 29: | Line 29: | ||
| from allthingstalk import Client, Device, NumberAsset | from allthingstalk import Client, Device, NumberAsset | ||
| + | |||
| + | # Parameters used to authorize and identify your device | ||
| + | # Get them on maker.allthingstalk.com | ||
| + | DEVICE_TOKEN = '< | ||
| + | DEVICE_ID = '< | ||
| class RandomDevice(Device): | class RandomDevice(Device): | ||
| temperature = NumberAsset(unit=' | temperature = NumberAsset(unit=' | ||
| - | client = Client('your Device token') | + | client = Client(DEVICE_TOKEN) |
| - | device = RandomDevice(client=client, | + | device = RandomDevice(client=client, |
| while True: | while True: | ||
| Line 53: | Line 58: | ||
| </ | </ | ||
| - | În Python, folosiți următorul exemplu pentru a deschide o conexiune serială cu placa Sparrow și a citi datele: | + | În Python, folosiți următorul exemplu pentru a deschide o conexiune serială cu placa Sparrow și a citi datele. Va trebui să instalați în prealabil biblioteca // |
| + | |||
| + | <code shell> > sudo pip3 install pyserial</ | ||
| <code python> | <code python> | ||
| Line 65: | Line 72: | ||
| while True: | while True: | ||
| line = ser.readline() | line = ser.readline() | ||
| - | print line | + | print(line) |
| sleep(1.0) | sleep(1.0) | ||
| </ | </ | ||
| Line 86: | Line 93: | ||
| # Parameters used to authorize and identify your device | # Parameters used to authorize and identify your device | ||
| # Get them on maker.allthingstalk.com | # Get them on maker.allthingstalk.com | ||
| - | DEVICE_TOKEN = 'maker: | + | DEVICE_TOKEN = '< |
| - | DEVICE_ID = 'Vjt9nzCDYgQI4Dp6iEzP4hak' | + | DEVICE_ID = '< |
| Line 112: | Line 119: | ||
| < | < | ||
| - | În mod similar, puteți să adăugați un actuator cu input analogic | + | În mod similar, puteți să adăugați un actuator cu input analogic. |
| Folosiți următorul exemplu de cod pentru a-l testa: | Folosiți următorul exemplu de cod pentru a-l testa: | ||
| <code python> | <code python> | ||
| - | from devicehub | + | import time |
| - | from time import sleep | + | from allthingstalk |
| - | PROJECT_ID | + | # Parameters used to authorize and identify |
| - | DEVICE_UUID | + | # Get them on maker.allthingstalk.com |
| - | API_KEY | + | DEVICE_TOKEN |
| - | AN_SENSOR_NAME | + | DEVICE_ID |
| - | | ||
| - | def act1_callback(payload): | ||
| - | """ | ||
| - | :param payload: mqtt payload message | ||
| - | """ | ||
| - | print ACT1.state | + | class LedActuator(Device): |
| + | picker = IntegerAsset(kind=Asset.ACTUATOR) | ||
| - | project = Project(PROJECT_ID) | ||
| - | device = Device(project, | ||
| - | ACT1 = Actuator(Actuator.ANALOG, ACTUATOR_NAME1) | + | # Authorize and connect your device with the Cloud |
| + | client | ||
| + | device = LedActuator(client=client, id=DEVICE_ID) | ||
| - | device.addActuator(ACT1, | ||
| - | try: | + | @LedActuator.command.picker |
| - | while True: | + | def on_picker(device, |
| - | pass | + | print('Led brightness updated to %s.' |
| - | except KeyboardInterrupt: | + | |
| - | print 'Goodbye!' | + | |
| + | |||
| + | while True: | ||
| + | print(' | ||
| + | time.sleep(5) | ||
| </ | </ | ||
| - | < | + | < |