Home/Support/Support Forum/dia data access from Python app
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

dia data access from Python app

0 votes
I'm new to iDigi and trying to do a few evaluation tasks. I have data channels from an X4 w/ Zigbee modules populating data streams that I can access through the iDigi web UI. I am trying to write/modify some basic Python scripts to pull the data from the iDigi servers. Although I can access certain high level data with the Python app, I am getting various errors trying to get channel data. I have tried to base the Python scripts on examples I have found on the Digi web site and latest Idigi Web Services Programming Guide. Input into my mistakes would be apprecaited. Here is the Python code I am using with various commands I have been trying (one at a time). Where applicable, I included the section where I got the syntax from the programming guide.

import httplib
import base64
# create HTTP basic authentication string, this consists of
# "username:password" base64 encoded
auth = base64.encodestring("%s:%s" % (username, password))[:-1]

webservice = httplib.HTTP("my.idigi.com", 80)
# to what URL to send the request with a given HTTP method
# webservice.putrequest("GET", "/ws/DiaChannelDataHistoryFull?condition=dcdUpdateTime>'2013-01-16T21:34:18.000Z'")

# webservice.putrequest("GET", "/ws/DiaChannelDataFull")

# webservice.putrequest("GET", "/ws/DeviceCore") # lists all gateways registered with iDigi account

# webservice.putrequest("GET", "/ws/XbeeCore") # lists all XBee resources registered with iDigi account

# webservice.putrequest("GET", "/ws/ResourcePath") # lists of resources - error 403

# returns 403, Forbidden, same error from browser
# webservice.putrequest("GET", "/ws/dia/channel/00000000-00000000-00409DFF-FF4BDB8A/sensor0/light/")

# returns 400, Bad Request (from section 17.3)
webservice.putrequest("GET", "/ws/DataPoint/dia/Channel/00000000-00000000-00409DFF-FF4BDB8A/sensor0/light")

# webservice.putrequest("GET", "/ws/DataStream") # works

# returns 505, HTTP Version Not Supported, works from browser URL bar (from section 4.3)
# webservice.putrequest("GET", "/ws/DiaChannelDataFull/?condition=devConnectwareId='00000000-00000000-00409DFF-FF4BDB8A' and dcChannelName='humidity'")

# add the authorization string into the HTTP header
webservice.putheader("Authorization", "Basic %s"%auth)
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")

# get the response
statuscode, statusmessage, header = webservice.getreply()
response_body = webservice.getfile().read()

# print the output to standard out
print (statuscode, statusmessage)
print response_body
asked Feb 1, 2013 in Python by dmarsell New to the Community (2 points)

Please log in or register to answer this question.

3 Answers

0 votes
webservice.putrequest("GET", "/ws/ResourcePath") # lists of resources - error 403
ResourcePath is just an example in the guide I believe as a placeholder for various supported resources like DeviceCore or XbeeCore.

webservice.putrequest("GET", "/ws/dia/channel/00000000-00000000-00409DFF-FF4BDB8A/sensor0/light/")
I'm not sure where this example came from, but it is wrong. The appropriate query would look like:

webservice.putrequest("GET", "/ws/DataPoint/dia/Channel/00000000-00000000-00409DFF-FF4BDB8A/sensor0/light")
This one should have a lower case c, like: /ws/DataStream/dia/channel/00000000-00000000-00409DFF-FF4BDB8A/sensor0/light

webservice.putrequest("GET", "/ws/DiaChannelDataFull/?condition=devConnectwareId='00000000-00000000-00409DFF-FF4BDB8A' and dcChannelName='humidity'")
I think the problem here is that you need to appropriately URL encode special characters like spaces in the url. There are better ways to do it in python (which I don't know without searching the APIs), but I've hand encoded the spaces so you can try this: /ws/DiaChannelDataFull/?condition=devConnectwareId='00000000-00000000-00409DFF-FF4BDB8A'%20and%20dcChannelName='humidity'

answered Feb 1, 2013 by cpopp Seasoned Professional (151 points)
0 votes

Thanks for the help and corrections. Commands are working as expected now. Assume that DiaChannelData example you gave was supposed to be DiaChannelDataFull.

answered Feb 5, 2013 by dmarsell New to the Community (2 points)
0 votes
I'm using this example to build a webapp, but I cannot understand why I am getting only one value (the most recent) from the request I'm doing.

My query starts with /ws/DataStream/ + all the address + ?rollupMethod=sum&rollupInterval=week

(200, 'OK')
<?xml version="1.0" encoding="ISO-8859-1"?>

But my DataStream is size = 1. How I can get the rest of the values?
answered Aug 2, 2013 by Hector New to the Community (1 point)