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
This code wraps all the functions necessary to make your object work with Live Objects.
5
5
6
6
You can declare parameters, which you can later update OTA from Live objects. You can also create commands to trigger actions remotely.
7
-
Only thing u must do yourself is connecting the board with internet.
7
+
Only thing you must do yourself is connecting the board with internet.
8
8
9
9
Code uses MQTT connection to exchange data with Live objects under the hood to keep your parameters up to date or execute the commands received without you having to take care of them (apart from writing the code of these commands, of course).
- Python for Windows needs [python-certifi-win32](https://pypi.org/project/python-certifi-win32/)
23
26
- uPython needs [umqttsimple, umqttrobust and ssl](https://github.com/micropython/micropython-lib)
24
27
25
28
## How to use ##
26
29
27
-
1. Log in to [Live Objects](https://liveobjects.orange-business.com) or request a [trial account](https://liveobjects.orange-business.com/#/request_account) (up to 10 devices for 1 year) if you don't have one.
28
-
2. Create an [API key](https://liveobjects.orange-business.com/#/administration/apikeys) for your device. Give it a name, select the *Device access* role and validate. Copy the key.
29
-
3. Clone or download the directory from Github.
30
-
4. Change **\<APIKEY\>** in sketches to one you generated
31
-
5. Run script
30
+
1. Log in to [Live Objects](https://liveobjects.orange-business.com) or request a [trial account](https://liveobjects.orange-business.com/#/request_account) (up to 10 devices for 1 year) if you don't have one,
31
+
2. Create an [API key](https://liveobjects.orange-business.com/#/administration/apikeys) for your device. Give it a name, select the *Device access* role and validate. Copy the key,
32
+
3. Clone or download the directory from Github,
33
+
4. Change **\<APIKEY\>** in `credentials.py` to one you generated,
34
+
5. Run selected `.py`script
32
35
33
36
## Developer guide ##
34
37
35
38
### Constructor ###
36
39
37
-
Constructor of LiveObjects looks like this
40
+
Constructor of LiveObjects looks like below:
38
41
39
42
```Python
40
-
lo = LiveObjects.Connection("mqttID",LiveObjects.NONE,"<APIKEY>", debug=True)
43
+
lo = LiveObjects.Connection()
41
44
```
42
45
43
-
First parameter is ID of the device, second is type of connection security ( NONE / SSL), third is Api Key to LiveObjects and last is debug mode, if you don't want to output debug messages set it to False. You can also use `lo.setDebug(False)`.
You can update over the air some parameters of your sketch using Live Objects's parameters. Parameters and Commands must be declared **before** your device connects to Live Objects.
57
+
You can update over the air some parameters of your script using Live Objects's parameters. Parameters and Commands must be declared **before** your device connects to Live Objects.
57
58
58
59
You can declare parameters with the `addParameter()` instruction, which accepts the following arguments:
59
60
- the label of your parameter as it will be displayed on Live Objects;
@@ -66,24 +67,24 @@ To retrieve a parameter use function `getParameter()` which takes following argu
Further reading on Live Objects' [Parameters](https://liveobjects.orange-business.com/doc/html/lo_manual.html#_configuration).
84
85
85
86
### Declare commands ###
86
-
Commands lets you trigger specific actions on your device from Live Objects. Parameters and Commands must be declared _before_ your device connects to Live Objects.
87
+
Commands let you trigger specific actions on your device from Live Objects. Parameters and Commands must be declared _before_ your device connects to Live Objects.
87
88
88
89
Commands can be declared using the `addcommand()` instruction, which accepts the following arguments:
89
90
- the label of your command
@@ -92,153 +93,134 @@ Commands can be declared using the `addcommand()` instruction, which accepts the
92
93
lo.addParameter("a command", myCallback);
93
94
```
94
95
95
-
The callback function should take 1 parameter and return dictonary
96
+
The callback function should take 1 parameter and return dictionary:
96
97
```Python
97
98
defmyCallback(args={}):
98
-
// do stuff
99
-
return {}
99
+
# do stuff
100
+
return {}
100
101
```
101
102
102
103
Arguments and response are optional when using commands, but they can be useful if you want to pass parameters to your function. For instance, you could define a `play tone` command that will use some parameters like the frequency of the tone, or its duration.
103
-
- Any incoming arguments will be passed as member of a dictonary
104
-
- You can pass response arguments in the form of a dictonary by returning them
104
+
- Any incoming arguments will be passed as member of a dictionary
105
+
- You can pass response arguments in the form of a dictionary by returning them
105
106
```Python
106
107
defplayTone(args={}):
107
-
duration = args["duration"]
108
-
frequency = args["frequency"]
109
-
// play the tone accordingly to arguments
110
-
...
111
-
return {"I played":"the tone"}
112
-
}
108
+
duration = args["duration"]
109
+
frequency = args["frequency"]
110
+
# play the tone accordingly to arguments
111
+
# ...
112
+
return {"I played": "the tone"}
113
113
114
114
defsetup():
115
-
lo.addCommand("play tone", playTone)
115
+
lo.addCommand("play tone", playTone)
116
116
```
117
-
> :warning:**Command name and arguments are case-sensitive when creating the command on Live Objects.**: On the opposite, there is no specific order for specifying the command arguments.
117
+
> Warning: **Command name and arguments are case-sensitive when creating the command on Live Objects.**: On the opposite, there is no specific order for specifying the command arguments.
118
118
119
119
Further reading on Live Objects' [Commands](https://liveobjects.orange-business.com/doc/html/lo_manual.html#MQTT_DEV_CMD).
120
120
121
121
### Sending data ###
122
122
You can send data very easily to Live Objects.
123
123
124
124
#### Dead simple method ####
125
-
Compose your payload using the `addToPayload()` instruction. You will need to provide a label for your value, and the data itself. You data can be of any simple type.
125
+
Compose your payload using the `addToPayload()` instruction. You will need to provide a label for your value, and the data itself. Your data can be of any simple type.
126
126
127
127
Data is added on each call to `addToPayload()`, so repeat the instruction if you have multiple data to send. When your payload is ready, send it using `sendData()`. That simple.
128
128
```Python
129
-
value=21
130
-
myOtherValue=37
129
+
VALUE=21
130
+
MY_OTHER_VALUE=37
131
131
132
132
deffoo():
133
-
// collect data
134
-
lo.addToPayload("my data", value)
135
-
lo.addToPayload("my other data", myOtherValue)
136
-
lo.sendData() # send to LiveObjects
133
+
# collect data
134
+
lo.addToPayload("my data", VALUE)
135
+
lo.addToPayload("my other data", MY_OTHER_VALUE)
136
+
lo.sendData() # send to LiveObjects
137
137
```
138
138
139
-
As soon the data is send, your payload is cleared and waiting for the next sending.
139
+
As soon the data is sent, your payload is cleared and waiting for the next sending.
140
140
141
-
### Advanced payload feautres ###
141
+
### Advanced payload features ###
142
142
```Python
143
-
#add "model" property to your message
144
-
lo.addModel("exampleName")
143
+
# Add "model" property to your message
144
+
lo.addModel("exampleName")
145
145
146
-
#Add "tag" property to your message
147
-
lo.addTag("kitchen")
148
-
lo.addTags(["humidity","bathroom"])
146
+
#Add "tag" property to your message
147
+
lo.addTag("kitchen")
148
+
lo.addTags(["humidity","bathroom"])
149
149
150
-
#Use your object as payload (this function doesn't append current paylod)
151
-
obj =["example":"value", "example2":"value2" ]
152
-
lo.setObjectAsPayload(obj)
150
+
#Use your object as payload (this function doesn't append current payload)
151
+
obj ={"example":"value", "example2":"value2"}
152
+
lo.setObjectAsPayload(obj)
153
153
```
154
154
155
155
156
156
### Connect, disconnect and loop ###
157
157
You can control the connection and disconnection of your device using `connect()` and `disconnect()`.
158
158
159
159
160
-
161
160
In order to check for any incoming configuration update or command, you need to keep the `loop()` instruction in your main loop.
2.[umqttsimple, umqttrobust and ssl](https://github.com/micropython/micropython-lib)
178
177
3.[PuTTY](https://www.putty.org/) (for Windows)
179
178
180
-
## Installation steps ##
181
-
1. Copy files into device
182
-
```
183
-
ampy -pCOMXX put umqttrobus.py
184
-
ampy -pCOMXX put umqttsimple.py
185
-
ampy -pCOMXX put ssl.py
186
-
ampy -pCOMXX put LiveObjects //It will copy directory with its content
187
-
```
188
-
2. Prepare your sketch and save it as main.py then copy file into device
189
-
```
190
-
ampy -pCOMXX put main.py
191
-
```
192
-
3. Setup internet connection in boot.py file and upload it into device.
193
-
```Python
194
-
# This file is executed on every boot (including wake-boot from deepsleep)
195
-
#import esp
196
-
#esp.osdebug(None)
197
-
import uos, machine
198
-
#uos.dupterm(None, 1) # disable REPL on UART(0)
199
-
import gc
200
-
#import webrepl
201
-
#webrepl.start()
202
-
gc.collect()
203
-
204
-
205
-
#Network connection
206
-
import network
207
-
sta_if = network.WLAN(network.STA_IF)
208
-
ifnot sta_if.isconnected():
209
-
print('connecting to network...')
210
-
sta_if.active(True)
211
-
sta_if.connect('SSID', 'PASS')
212
-
whilenot sta_if.isconnected():
213
-
pass
214
-
print('network config:', sta_if.ifconfig())
215
-
```
216
-
You may want to get content of file first, then use
179
+
### Installation steps ###
180
+
181
+
1. Preparation
182
+
183
+
Change **\<APIKEY\>** in `credentials.py` to one you generated.\
184
+
Change **\<WIFI_SSID\>** and **\<WIFI_PASS\>** suitable to your WiFi.
185
+
186
+
187
+
2. Copy files into device
188
+
```Shell
189
+
>ampy -pCOMXX put umqttrobust.py
190
+
>ampy -pCOMXX put simple.py
191
+
>ampy -pCOMXX put LiveObjects // It will copy directory with its content
217
192
```
218
-
ampy -pCOMXX get boot.py
193
+
3. Prepare your script and save it as `main.py` then copy file into device. You can use one of example ones (`1_send_data.py`, ...) renaming it to `main.py`
194
+
```Shell
195
+
>ampy -pCOMXX put main.py
219
196
```
197
+
220
198
4. Connect to device and check if it's working using PuTTY
221
199
222
-
Crtl + D soft resets device
223
-
200
+
Ctrl + D soft resets device
201
+
224
202
Ctrl + C Stops currently running script
225
203
226
-
## Summary ##
227
-
After all steps content of the device should look like this
228
-
```
204
+
###Summary###
205
+
After all steps content of the device should look like below:
206
+
```Shell
229
207
>ampy -pCOMXX ls
230
208
/LiveObjects
231
209
/boot.py
232
210
/main.py
233
-
/ssl.py
234
211
/umqttrobust.py
235
-
/umqttsimple.py
212
+
/simple.py
236
213
237
214
>ampy -pCOMXX ls LiveObjects
238
215
/LiveObjects/Connection.py
239
216
/LiveObjects/__init__.py
240
-
/LiveObjects/certfile.cer
217
+
/LiveObjects/hal.py
218
+
/LiveObjects/credentials.py
241
219
```
242
220
221
+
## Example for LoPy / GPy ##
222
+
223
+
You can do the steps as above but better is to use [Pymakr plug-in](https://pycom.io/products/supported-networks/pymakr/) for **Visual Studio Code** or **Atom** delivered by [Pycom](https://pycom.io/). Plug-in supports code development, its upload to board and communication with board.
224
+
243
225
## Troubleshooting ##
244
226
If you are getting 'MQTT exception: 5' check your api key
0 commit comments