Python Code to retrieve data from Device to IBM Bluemix

0 votes

I need code for getting data from bluemix which is sent by this code

import RPi.GPIO as GPIO
import dht11
import time
import datetime
import ibmiotf.device

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

1
client.connect()



# read data using pin GPIO4
instance = dht11.DHT11(pin=4)

while True:
    result = instance.read()
    if result.is_valid():
        print("Last valid input: " + str(datetime.datetime.now()))
        temp=(" %d C" % result.temperature)
        print("temperature:" +temp)
        humid=("%d %%" % result.humidity)
    print("Humidity:" +humid)
       # print("Temperature: %d C" % result.temperature)
       # print("Humidity: %d %%" % result.humidity)
        print("Data is published into the cloued")
        Data={'Temperature' :temp, 'Humidity' :humid }
        client.publishEvent("status", "json", Data)

    time.sleep(1)
Sep 18, 2018 in IoT (Internet of Things) by Matt
• 2,270 points
1,304 views

1 answer to this question.

0 votes

You connect as a device -> import ibmiotf.device. A device can send events and receive commands. It can't receive events. To do this you need to connect as an application. You will import ibmiotf.application and have something like:

options = ibmiotf.application.ParseConfigFile(configFilePath)
appClient = ibmiotf.application.Client(options)

appClient.connect()
appClient.subscribeToDeviceEvents()

The config file should be like:

[application]
org=orgId
id=myApplication
auth-method=apikey
auth-key=key
auth-token=token

Where the auth-key/auth-token comes from the Apps part of your platform. You'll have to generate a set to connect as an application. The auth-method should be left as apikey.

That will list every event that arrives to your platform. You can make it more granular. 

answered Sep 18, 2018 by anonymous2
• 4,240 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

I cannot retrieve data from historian in Bluemix Watson IoT Platform

You're partially right! Earlier this month, the "built-in" ...READ MORE

answered Jan 11, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
1,143 views
0 votes
1 answer

How to use the data I receive from Azure IoT Hub?

The payload you receive will be a ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,808 views
0 votes
1 answer
0 votes
1 answer

How to read data from MQTT in Eclipse Paho?

You don't read data from a MQTT ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
941 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
0 votes
1 answer

Publishing commands to device in IBM IoT using MQTT in Java

If you are publishing from an application, ...READ MORE

answered Jul 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,506 views
0 votes
1 answer

Send data from cloud to aws iot thing

Your solution is not recommend because there ...READ MORE

answered Aug 2, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,400 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP