Having some difficulties... | ThingSpeak API | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Having some difficulties...
No permission to create posts
May 5, 2011
2:49 am

Forum Posts: 6
Member Since:
May 5, 2011
sp_UserOfflineSmall Offline

OK, below is my code that is causing a problem.  I've got a Channel with 4 fields.  The terminology is new to me.  I suppose a channel is for a device?  The fields are where the datastreams would go?

So I have a board with an xbee radio and 4 sensors on it.  I've got a hacked Asus wifi router hooked up with openwrt and python.  The python script is polling the various radios in my house.  One of them is the multi-sensor device I'm trying to set up in Thingspeak.

I've got it hard coded for field1 but eventually I'm going to want to pass in the field I want to update as a parametr and create the filed name (field1, field2, etc)

I'm getting an error:
Exception:  http://api.thingspeak.com:80  -  (7, 'no address associated with hostname.')

I think it is happening on the line:
conn.request("POST", "/update", params, headers)

Any help would be appreciated,

import urllib, urllib2, httplib
THINGSPEAKURL = "http://api.thingspeak.com"
THINGSPEAK_KEY = "mynumber" 

def logtothing(lnSensorNum, lnAvgUnits, lcThingSpeakKey, fieldnum):
    # lnSensorNum is the number of the xbee radio
    # lnAvgUnits is the average of the last 5 minutes
    # lcThingSpeakKey - the channel/device api key
    # fieldnum (1,2,3,4) is the ADC input from each of the 4 sensors - relates to the ADCs on the xbee (0,1,2,3)

    feedUrl = THINGSPEAKURL + ":80"
    fieldname = "field" + str(fieldnum +1)
    	params = urllib.urlencode({'field1': lnAvgUnits,'key':lcThingSpeakKey})
        headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
        conn = httplib.HTTPConnection(feedUrl)
        conn.request("POST", "/update", params, headers)
        response = conn.getresponse()
        data = response.read()

    except Exception, e:
        print "Exception: ", feedUrl, " - ", str(e)
        syslog.syslog("TLSM.logtothing exception: " + feedUrl + " - " + str(e)) 

May 5, 2011
2:50 am

Forum Posts: 6
Member Since:
May 5, 2011
sp_UserOfflineSmall Offline

Hard to read my post in the embedded forum...  Sorry.

May 5, 2011
8:44 am

Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

Based on the error message, it looks like you're not able to

resolve the correct IP address from the hostname.

Try using this instead:

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormier

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457