0

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?

ValerieLampkin
  • 2,620
  • 13
  • 27
user3442005
  • 103
  • 9
  • When you say you have successfully connected your Pi with Bluemix, do you mean you are able to publish, or did you just register it? What is your 6 character org ID? – ValerieLampkin Jun 09 '16 at 19:14
  • I am able to to see on the IBM Watson IoT platform page that my Raspberry Pi is connected. My org ID is s141xb – user3442005 Jun 09 '16 at 19:32
  • In your myCommandCallback, add a print statement, also printing cmd.event - does that show up when your bluemix app sends the message? Haven't looked at the imbiotf docs, but `deviceEventCallback` doesn't seem right, I'd have expected something like `deviceCommandCallback` – DisappointedByUnaccountableMod Jun 10 '16 at 06:01

0 Answers0