enableiot / iotkit-samples

Demonstration code for the IoT Kit
Other
43 stars 36 forks source link

IoTkitSimpleExample.py does not work on Edison #17

Closed jpwright closed 9 years ago

jpwright commented 9 years ago

I have my iotkit-agent setup and working on Edison. I'm able to send test data using iotkit-admin and view it in the Dashboard without problems. Here's the output of systemctl status:

root@erdos:~# systemctl status iotkit-agent
● iotkit-agent.service - iotkit-agent
   Loaded: loaded (/lib/systemd/system/iotkit-agent.service; disabled)
   Active: active (running) since Wed 2014-12-03 12:40:29 UTC; 34min ago
 Main PID: 1090 (node)
   CGroup: /system.slice/iotkit-agent.service
           └─1090 node /usr/bin/iotkit-agent

Dec 03 12:40:29 erdos systemd[1]: Started iotkit-agent.
Dec 03 12:40:32 erdos iotkit-agent[1090]: 2014-12-03T12:40:32.783Z - info: S....
Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.288Z - info: S....
Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.419Z - info: T...0
Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.435Z - info: U...4
Hint: Some lines were ellipsized, use -l to show in full.

and netstat:

root@erdos:~# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:58888           0.0.0.0:*               LISTEN      230/node
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      206/broker_mqtts32
tcp        0      0 127.0.0.1:7070          0.0.0.0:*               LISTEN      1090/node
tcp6       0      0 :::22                   :::*                    LISTEN      1/init
udp        0      0 0.0.0.0:38081           0.0.0.0:*                           158/systemd-timesyn
udp        0      0 0.0.0.0:48356           0.0.0.0:*                           207/mdnsd
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           207/mdnsd
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           207/mdnsd
udp        0      0 0.0.0.0:41234           0.0.0.0:*                           1090/node
udp6       0      0 :::55515                :::*                                207/mdnsd
udp6       0      0 :::5353                 :::*                                207/mdnsd

However, running the Python script does not successfully send data.

It doesn't look like either the TCP or UDP listeners actually respond with anything so I'm not sure how to debug this.

Note: It might be worth noting somewhere that for Edison the script should be changed to use /sys/class/thermal/thermal_zone3/temp to read the core temperature instead of thermal_zone0.

Note 2: How can I test the UDP listener on Edison? It doesn't look like the example with nc works when I try it:

root@erdos:~# echo -n '{ "n": "coretemp", "v": "5"}' | nc -u 127.0.0.1 7070
BusyBox v1.22.1 (2014-08-15 22:26:53 CEST) multi-call binary.

Usage: nc [IPADDR PORT]

Does the version of nc on edison not support UDP?

scalectrix commented 9 years ago

nc on default Edison image doesn't support udp. Which Python script are you talking about? Better submit issues / questions on communities.intel.com Makers forum On Dec 3, 2014 5:22 PM, "Jason Wright" notifications@github.com wrote:

I have my iotkit-agent setup and working on Edison. I'm able to send test data using iotkit-admin and view it in the Dashboard without problems. Here's the output of systemctl status:

root@erdos:~# systemctl status iotkit-agent ● iotkit-agent.service - iotkit-agent Loaded: loaded (/lib/systemd/system/iotkit-agent.service; disabled) Active: active (running) since Wed 2014-12-03 12:40:29 UTC; 34min ago Main PID: 1090 (node) CGroup: /system.slice/iotkit-agent.service └─1090 node /usr/bin/iotkit-agent

Dec 03 12:40:29 erdos systemd[1]: Started iotkit-agent. Dec 03 12:40:32 erdos iotkit-agent[1090]: 2014-12-03T12:40:32.783Z - info: S.... Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.288Z - info: S.... Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.419Z - info: T...0 Dec 03 12:40:39 erdos iotkit-agent[1090]: 2014-12-03T12:40:39.435Z - info: U...4 Hint: Some lines were ellipsized, use -l to show in full.

and netstat:

root@erdos:~# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:58888 0.0.0.0:* LISTEN 230/node tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 206/broker_mqtts32 tcp 0 0 127.0.0.1:7070 0.0.0.0:* LISTEN 1090/node tcp6 0 0 :::22 :::* LISTEN 1/init udp 0 0 0.0.0.0:38081 0.0.0.0:* 158/systemd-timesyn udp 0 0 0.0.0.0:48356 0.0.0.0:* 207/mdnsd udp 0 0 0.0.0.0:5353 0.0.0.0:* 207/mdnsd udp 0 0 0.0.0.0:5353 0.0.0.0:* 207/mdnsd udp 0 0 0.0.0.0:41234 0.0.0.0:* 1090/node udp6 0 0 :::55515 :::* 207/mdnsd udp6 0 0 :::5353 :::* 207/mdnsd

However, running the Python script does not successfully send data.

It doesn't look like either the TCP or UDP listeners actually respond with anything so I'm not sure how to debug this.

Note: It might be worth noting somewhere that for Edison the script should be changed to use /sys/class/thermal/thermal_zone3/temp to read the core temperature instead of thermal_zone0.

Note 2: How can I test the UDP listener on Edison? It doesn't look like the example with nc works when I try it:

root@erdos:~# echo -n '{ "n": "coretemp", "v": "5"}' | nc -u 127.0.0.1 7070 BusyBox v1.22.1 (2014-08-15 22:26:53 CEST) multi-call binary.

Usage: nc [IPADDR PORT]

Does the version of nc on edison not support UDP?

— Reply to this email directly or view it on GitHub https://github.com/enableiot/iotkit-samples/issues/17.

jpwright commented 9 years ago

I'm talking about the python example IoTkitSimpleExample.py.

I'll submit to maker.intel.com as well. Thanks.

jtaryma commented 9 years ago

Everything should be fixed now. Please check if you still experience problems.

1tylermitchell commented 9 years ago

Any resolution here? I'm trying the same echo statement but getting stuck at same nc usage notice.

marcinma commented 9 years ago

By default iotkit-agent UDP is listening on 41234 port, so proper command should look like:

echo -n '{ "n": "temp", "v": "5"}' | nc -u 127.0.0.1 41234

assuming device has 'temp' component it will work (also IoTkitSimpleExample.py will work if you have 'temp' component attached to device)

jmontague001 commented 8 years ago

Is there any fix for this? Im having this exact problem. I've tried all the different echo statements but get the same nc usage notice every time? Any help would be much appreciated.

marcinma commented 8 years ago

@jmontague001 please provide more information, logs, commands, results etc. as you can see bug was reported in 2014 and we've made some fixes. Also try to use my command for nc usage.

jmontague001 commented 8 years ago

Hi marcinma, thanks for your message. What I'm trying to do is run the IOT Cloud Analytics example that is on the eclipse IDE in c/c++. I've been following this guide: https://software.intel.com/en-us/intel-iot-platforms-getting-started-cloud-analytics And can get to the point where I can send values successfully to the analytics website using the "iotkit-admin observation temperature 10" command.

root@pearl-edison:~# iotkit-admin observation temperature 10 2016-06-10T09:06:00.191Z - info: Submitting: n=temperature, v=10 2016-06-10T09:06:01.725Z - info: Response received: response=none detail, status=0 2016-06-10T09:06:01.837Z - info: Observation Sent response=none detail, status=0

But the problem im having is when trying to send values using the UDP local agent. If i try this from the Edison terminal this is what the message I receive:

root@pearl-edison:~# systemctl status iotkit-agent -l ● iotkit-agent.service - iotkit-agent Loaded: loaded (/lib/systemd/system/iotkit-agent.service; disabled) Active: active (running) since Fri 2016-06-10 09:07:05 UTC; 5min ago Main PID: 380 (node) CGroup: /system.slice/iotkit-agent.service └─380 node /usr/bin/iotkit-agent

Jun 10 09:07:05 pearl-edison systemd[1]: Started iotkit-agent. Jun 10 09:07:10 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:10.081Z - info: Device has already been activated. Updating ... Jun 10 09:07:10 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:10.117Z - info: Updating metadata... Jun 10 09:07:10 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:10.170Z - info: Metadata updated. Jun 10 09:07:12 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:12.258Z - info: Starting listeners... Jun 10 09:07:12 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:12.579Z - info: Connecting to ws.us.enableiot.com:443... Jun 10 09:07:12 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:12.612Z - info: TCP listener started on port: 7070 Jun 10 09:07:12 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:12.627Z - info: UDP listener started on port: 41234 Jun 10 09:07:13 pearl-edison iotkit-agent[380]: 2016-06-10T09:07:13.887Z - info: WSConnector: Connection successful to: ws.us.enableiot.com:443

root@pearl-edison:~# echo -n '{ "n": "temperature", "v": "5"}' | nc -u 127.0.0.1 41234 BusyBox v1.22.1 (2016-03-08 12:09:34 PST) multi-call binary.

Usage: nc [IPADDR PORT]

I then tried opening up a seperate terminal to send the echo command from but when i put 127.0.0.1 as the host address i get a error message saying: "Network error: connection refused".

If i try sending "nc 127.0.0.1 41234" in the edison terminal I get a similar message:

root@pearl-edison:~# nc 127.0.0.1 41234 nc: can't connect to remote host (127.0.0.1): Connection refused

Appologies if I'm doing something stupid, I'm new to this.

pskindel commented 8 years ago

Hi jmontague001! The problem is with nc included in BusyBox. Since it is limited version of standalone netcat, it doesn't support UDP mode. That's why you see Usage message when using -u option. Connection refused is caused by nc connection in TCP mode, which is wrong (agent listens on 41234 UDP port). To mitigate this problem you could: compile standalone nc from sources for Edison or use netcat from computer - remotely sending an observation to Edison. But please note that in latter case, you should use Edison's IP visible from network (not 127.0.0.1 nor localhost). Looking forward to your response. We're here to help :)