I referred to the following tutorial: https://developer.ibm.com/bluemix/2015/04/02/tutorial-using-a-raspberry-pi-python-iot-twilio-bluemix/
I connected my Raspberry Pi with an application on Bluemix using the IoT Foundation. I could get everything up and running except for the client.py (@step 36 in the tutorial). Here's the error message I got:
client.py:9: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
Traceback (most recent call last):
File "client.py", line 23, in <module>
options = ibmiotf.application.ParseConfigFile("/home/pi/device.cfg")
File "/usr/local/lib/python2.7/dist-packages/ibmiotf/application.py", line 501, in ParseConfigFile
appType = parms.get(sectionHeader, "type", "standalone")
File "/usr/lib/python2.7/ConfigParser.py", line 618, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'type' in section: 'application'
I found the error to have been coming from the missing "type" section in the config file (device.cfg). But, the file structure listed (@step 35 of the tutorial) doesn't say, that you need a "type". So, I just used the device type(raspberrypi), which I created in the IoT Foundation earlier. Now, I could successfully connect to the IoT Foundation.
But, the issue, now, is that absolutely nothing happens upon pressing the button on my Raspberry Pi or even pressing the "Turn light on/off" button on the web application.
When I checked the logs of the python app using "./cf logs myappname -recent", the following is the output I got:
2016-01-29T08:38:49.10+0100 [App/0] OUT on
2016-01-29T08:38:49.10+0100 [App/0] ERR 188.8.131.52 - - [29/Jan/2016 07:38:49] "POST /light/on HTTP/1.1"; 302 -
2016-01-29T08:38:49.34+0100 [App/0] ERR 184.108.40.206 - - [29/Jan/2016 07:38:49] "GET / HTTP/1.1"; 200 -
2016-01-29T08:38:49.56+0100 [RTR/1] OUT myappname.mybluemix.net - [29/01/2016:07:38:49 +0000] "GET / HTTP/1.1" 200 0 751 "http://myappname.mybluemix.net/" ";Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" 220.127.116.11:39460 x_forwarded_for:"18.104.22.168"x_forwarded_proto:"http" vcap_request_id:myrequestid response_time:0.31228492 app_id:myapp_id x_global_transaction_id:mytransactionid;
2016-01-29T08:40:08.32+0100 [App/0] OUT off
2016-01-29T08:40:08.33+0100 [App/0] ERR 22.214.171.124 - - [29/Jan/2016 07:40:08] "POST /light/off HTTP/1.1" 302 -
2016-01-29T08:40:08.51+0100 [App/0] ERR 126.96.36.199 - - [29/Jan/2016 07:40:08] "GET / HTTP/1.1" 200 -`
I also took this up with the tutorial's writer, Jeff. He advised me to double check if the Pi and the Bluemix app are both listening on the same topic or not. And, I should be able to see messages coming through in the IoT service.
So, I'm clueless to what this means or how I should be doing this now. I would appreciate any help at all, so please do share any ideas on the same.
Also, here's the output on my Pi upon starting the application with: sudo python client.py
2016-02-01 14:36:23,221 ibmiotf.application.Client WARNING Unable to encrypt messages because TLSv1.2 is unavailable (MQTT over SSL requires at least Python v2.7.9 or 3.4 and openssl v1.0.1)
2016-02-01 14:36:23,716 ibmiotf.application.Client INFO Connected successfully: A:69wm3f:aaaafdsfsd45641safsda2313
The first time I press the on/off buttons after the client starts, following is the output that I get on the Pi:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 505, in run
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2287, in _thread_main
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1261, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 811, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1073, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1475, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1943, in _packet_handle
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2118, in _handle_publish
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2268, in _handle_on_message
t(self, self._userdata, message)
File "/usr/local/lib/python2.7/dist-packages/ibmiotf/application.py", line 423, in __onDeviceEvent
if self.deviceEventCallback: self.deviceEventCallback(event)
File "client.py", line 17, in myCommandCallback
command = cmd.payload["d"]["command"]
TypeError: string indices must be integers, not str
The way it looks, it seems to me that messages from the IoT Foundation are successfully reaching the client.
Following are the IDs I've set(same IDs for all) on the IoT Foundation, the environment variable of the Bluemix Python app and on my Raspberry Pi:
- IoT Foundation ID: afdsfsd45641safsda2313
- Bluemix Python app ID: afdsfsd45641safsda2313
- Raspberry Pi ID in device.cfg: afdsfsd45641safsda2313