I must be missing something pretty simple. I’ve got pretty good experience with Arduino, web/ip standards and python, but I just cannot make this work.
I’ve got the latest tinker firmware installed on my core (sourced from the github page). The tinker iPhone app seems to work fine (turns on D7 when requested, etc). However, for the life of me, I cannot get my own REST queries to make the core do anything.
I’m using the following bit of code:
from hammock import Hammock
from pprint import pprint
spark = Hammock('https://api.spark.io/v1')
access_token='TOKEN'
device_id='ID'
me = spark.devices(device_id).digitalwrite.POST(params={'access_token':access_token,'args': 'D7,HIGH'})
Now, for those of you not familiar with the Hammock library, its just an easy way to use RESTful APIs. The resulting URL request that comes out of that is:
POST https://api.spark.io/v1/devices/DEVICEID/digitalwrite?access_token=TOKEN&args=D7%2CHIGH'
That seems pretty reasonable to me given the API documentation, but I always end up with a -1 return value:
{u'connected': True,
u'id': u'DEVICEID',
u'last_app': None,
u'name': u'cowgerhome',
u'return_value': -1}
I’ve gone through the digital write() function in the tinker firmware and change it such that each failure condition returns a different negative value, and continue to end up with ‘-1’, indicating that this snippet is somehow failing:
int pinNumber = command.charAt(1) - '0';
if (pinNumber< 0 || pinNumber >7) return -1;
I’ve even gone so far as to make that function statically return ‘42’ as the only statement. THAT seems to work just fine, so something is going on with the snippet above - but its the stock code, so there must be something wrong in my request. Ideas?