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,260 points
38 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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. See the api guide which also references a sample app on github.

answered Sep 18, 2018 by anonymous2
• 4,260 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 in IoT (Internet of Things) by Upasana
• 7,680 points
37 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,100 points
45 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,260 points
47 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
24 views
+4 votes
6 answers
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,260 points
318 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,260 points
41 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.