I have built a small setup with the Raspberry Pi which consists of a LED. I have successfully connected my Pi with Bluemix. I wrote a small code which turns on and off the led from a mybluemix.net webpage (function myCommandcallback).
import RPi.GPIO as GPIO
import time
import os, json
import ibmiotf.application
import uuid
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.OUT)
client = None
def myCommandCallback(cmd):
if cmd.event == "light":
payload = json.loads(cmd.payload)
command = payload["command"]
print command
if command == "on":
GPIO.output(17, GPIO.HIGH)
elif command == "off":
GPIO.output(17, GPIO.LOW)
try:
options = ibmiotf.application.ParseConfigFile("/home/pi/device.cfg")
options["deviceId"] = options["id"]
options["id"] = "aaa" + options["id"]
client = ibmiotf.application.Client(options)
client.connect()
client.deviceEventCallback = myCommandCallback
client.subscribeToDeviceEvents(event="light")
while True:
GPIO.wait_for_edge(18, GPIO.FALLING)
print "Button Pushed"
myData = {'buttonPushed' : True}
client.publishEvent("raspberrypi", options["deviceId"], "input", "json", myData)
time.sleep(0.2)
except ibmiotf.ConnectionException as e:
print e
When I click the button to turn on the LED on the webpage, the sensor information on the IBM IoT platform shows "light on", but the LED doesn't actually turn on. Is there anyway to check on the Pi if the information has been received?