The following example illustrates posting a message form M1-N1 over TCP/IP
Test server address is dweet.io
Test server port is 80
Summary
After the M1-N1 has completed the boot up process. Serial API commands can be used to setup the server details. A socket is opened. Messages are sent and and response is obtained and delivered.
Method 1
+tcp_open,host:iot-chirpstack.aws.signetik.com,port:5731
+rsp,result:0,socket:4
+tcp_send,socket:4,data:SENDDATA
+rsp,result:0
+notify,event:tcp_receive,data:RECVDATA
+tcp_close,socket:4
+rsp,result:0
Note that +tcp_open, +tcp+send, +tcp_close are the command you would issue.
+rsp, +notify lines are responses and notifications from M1-N1. These are indented in the above snippet for clarity
Method 2
In the following example +tcp_open, +set, +http_get, +tcp_close are commands issued by user. +rsp are responses from M1-N1 to commands. +notify are asynchronous notifications sent by M1-N1
Example:
1. Open a TCP socket by specifying server address and port
+tcp_open,host:dweet.io,port:80
Socket number is returned in the response. Note this for use later.
+rsp,result:0,socket:3
2. Set server address
+set,server_address:dweet.io
Expected response from M1-N1 echoes the setting
+rsp,server_address:dweet.io
3. Send a message, by constructing the URI. In the following example. Create your own path. In this example the path on test server for this message is dweet/for/signetik
+set,uri:/dweet/for/signetik?param1=234
Expected response from M1-N1 echoes command
+rsp,uri:/dweet/for/signetik?param1=234
4. Listen to response from server.
Note that the socket number specified for listening is the same as obtained from tcp_open command above.
+http_get,socket:3
Response indicates any error codes. 0: no error.
+rsp,result:0
5. Receive message
Messages received from will be provided as they arrive.
+notify,event:tcp_receive,data:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Content-Length: 193
Date: Wed, 26 Jan 2022 17:17:21 GMT
Connection: keep-alive
{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"signetik","created":"2022-01-26T17:17:20.975Z","content":{"param1":234},"transaction":"89fcbe51-1811-4daa-a981-271343f7ff08"}}
6. Close socket
+tcp_close,socket:3
Response indicates any error codes. 0: no error.
+rsp,result:0
With the above example, the message sent to test server can be viewed at the custom path chosen for this test in the first step dweet/for/signetik
https://dweet.io/get/latest/dweet/for/signetik
Comments
0 comments
Please sign in to leave a comment.