I'm experimenting with my rPi and trying to get it to log temperature data and post this to a self-hosted RESTful API.
I'm having issues successfully posting data to the API - here's my test code:
[rPi Python code]
Code: Select all
import urllib
import urllib2
url = 'http://doopcreations.com/raspberry/api/data'
params = urllib.urlencode({
'item': 'temperature',
'data': '25.00'
})
print("Posting data: " + params)
response = urllib2.urlopen(url, params).read()
print(response){"error":{"text":SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'item' cannot be null}}
Notes:
I've also tried to update my DB to allow NULL values - this results in only null values being inserted - ie/ it seems that my python code isn't posting data.......
Any ideas on how I can resolve this?
------------
[Background]
I've build a simple API (public with no authentication for the moment) - using slimPHP/mySQL:
I've tested this using a RESTful tool and am able to successfully POST to the API.
--
GET:
http://doopcreations.com/raspberry/api/data
returns a JSON array of all items
id
item
data
created
--
POST:
http://doopcreations.com/raspberry/api/data
Parameters:
item:
data:
in JSON ie/
{"item": "temp", "data": "25.123"}