|
1 | 1 | from uLiveObjectsSDK import * |
2 | 2 |
|
3 | | -def do_connect(): |
4 | | - import network |
5 | | - sta_if = network.WLAN(network.STA_IF) |
6 | | - if not sta_if.isconnected(): |
7 | | - print('connecting to network...') |
8 | | - sta_if.active(True) |
9 | | - sta_if.connect('LIKI', 'Newconnect75') |
10 | | - while not sta_if.isconnected(): |
11 | | - pass |
12 | | - print('network config:', sta_if.ifconfig()) |
13 | | - |
14 | | -do_connect() |
15 | | -lo = LiveObjects("PythonMQTT", 1883, "YOUR API KEY") |
| 3 | +lo = LiveObjects("PythonMQTT", 1883, "Your api key") |
16 | 4 |
|
17 | 5 | uptime = 0 |
18 | 6 | def foo(arg=""): |
19 | | - lo.outputDebug(INFO,"Wywolalem funkcje foo z argumentem ", arg) |
| 7 | + lo.outputDebug(INFO,"called function with foo arg ", arg) |
20 | 8 | return { "blinked" : "5 times"} |
21 | 9 |
|
| 10 | +last = time.time() |
| 11 | + |
| 12 | +#esp8266 esp32 |
| 13 | +# def do_connect(): |
| 14 | +# import network |
| 15 | +# sta_if = network.WLAN(network.STA_IF) |
| 16 | +# if not sta_if.isconnected(): |
| 17 | +# print('connecting to network...') |
| 18 | +# sta_if.active(True) |
| 19 | +# sta_if.connect('<SSID>', '<PASS>') |
| 20 | +# while not sta_if.isconnected(): |
| 21 | +# pass |
| 22 | +# print('network config:', sta_if.ifconfig()) |
| 23 | + |
22 | 24 |
|
23 | 25 | if __name__ == '__main__': |
| 26 | + #do_connect() |
24 | 27 | lo.addCommand("foo",foo) |
25 | 28 | lo.addParameter("messageRate",5 , INT) |
26 | 29 | lo.connect() |
27 | 30 | uptime = time.time() |
28 | 31 | while True: |
29 | | - lo.addToPayload("uptime", int(time.time()-uptime)) |
30 | | - lo.sendData() |
31 | | - lo.loop() |
32 | | - time.sleep(lo.getParameter("messageRate")) |
| 32 | + if(time.time()>=last+lo.getParameter("messageRate")): |
| 33 | + lo.addToPayload("uptime", int(time.time()-uptime)) |
| 34 | + lo.sendData() |
| 35 | + lo.loop() |
| 36 | + last = time.time() |
0 commit comments