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
116 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. 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
• 8,530 points
66 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,130 points
635 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
81 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 275 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
431 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
102 views