Thus I am sending ‘1’, which I hope toInt() would convert to 1, corresponding to D1 (tested by returning D1, D7 and getting 1 and 7 respectively), but I always get 0!
how are you calling the APIs? I’m using Spark-cli and i tested working.
int on(String args);
void setup(){
int i;
for(i=2;i<8;i++)
pinMode(i,OUTPUT);
Spark.function("on", on);
}
void loop(){
}
int on(String args)
{
int pin = args.toInt();
digitalWrite(pin, HIGH);
return pin;
}
CMD output:
C:\Users\Kenneth Lim>spark function call 48ff6a065067555008342387 on "1"
1
C:\Users\Kenneth Lim>spark function call 48ff6a065067555008342387 on "7
7
C:\Users\Kenneth Lim>spark function call 48ff6a065067555008342387 on 2
2
C:\Users\Kenneth Lim>spark function call 48ff6a065067555008342387 on 4
4
C:\Users\Kenneth Lim>spark function call 48ff6a065067555008342387 on 5
5
Hi Kenneth, thanks for replying. I’m using the PebbleKit JS via XMLHTTPRequest objects. Here’s how that happens:
var REST = function (url, type, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
callback(this.responseText);
};
xhr.open(type, url);
xhr.send();
};
After making the request using curl for Windows, I have found that the correct return_value is the same as that specified in the request. The problem must therefore be with the Pebble KS, as you proposed.
Substituted the XMLHTTPRequest with jQuery ajax but the problem still persists. Again, I know the Core is doing its job properly because of the Curl test. Strange…
The output is delivered to by Ubuntu VM terminal by pebble logs. The message received using Curl looks like this (where secret_token is substituted with my real access token!):
@kennethlimcp I recognise the ‘data’ being specified as a JSON dictionary, but am not familiar with Python enough to recognise the requests.post construct or module. Thanks though!