Hello,
I’m playing around with dweet.io by setting up a webhook and calling Spark.publish() whenever I push a button. When I press the button, I’m getting the expected messages. However, it looks like the webhook mechanism is constantly sending messages when I’m not pressing the button. The messages continue streaming even when I shut down the spark core. Is this right, or did I make a silly mistake somewhere?
// Use this curl command to test:
// curl -i https://dweet.io/listen/for/dweets/from/wqDweetTest1
// button is used to trigger ON/OFF state
int button = D5;
int light = D7;
bool onState;
void setup() {
pinMode(button, INPUT_PULLDOWN);
pinMode(light, OUTPUT);
onState = true;
}
// toggle onState and publish to dweet.io
void loop() {
if(digitalRead(button) == HIGH)
{
digitalWrite(light, HIGH);
if (onState == true)
Spark.publish("status", "ON");
else
Spark.publish("status", "OFF");
onState = !onState;
delay(400);
}
delay(300);
digitalWrite(light, LOW);
}
The webhook is as simple as it can be:
{
"eventName": "status",
"url": "https://dweet.io:443/dweet/for/wqDweetTest1",
"requestType": "POST"
}
Using curl to get a running log of output from dweet.io (and pressing the button a couple of times):
pc@raptor:~/workspaceArduino/sparktest$ curl -i https://dweet.io/listen/for/dweets/from/wqDweetTest1
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 17 Apr 2015 23:05:08 GMT
Connection: keep-alive
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:08.323Z\",\"content\":{\"event\":\"status\",\"data\":100001111,\"published_at\":\"2015-04-17T23:05:08.264Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d0
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:10.060Z\",\"content\":{\"event\":\"status\",\"data\":\"ON\",\"published_at\":\"2015-04-17T23:05:09.982Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d1
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:12.888Z\",\"content\":{\"event\":\"status\",\"data\":\"OFF\",\"published_at\":\"2015-04-17T23:05:12.817Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:14.074Z\",\"content\":{\"event\":\"status\",\"data\":100101214,\"published_at\":\"2015-04-17T23:05:14.013Z\",\"coreid\":\"54ff6a066678574948530467\"}}"
d0
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:15.102Z\",\"content\":{\"event\":\"status\",\"data\":\"ON\",\"published_at\":\"2015-04-17T23:05:15.043Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:15.747Z\",\"content\":{\"event\":\"status\",\"data\":100001202,\"published_at\":\"2015-04-17T23:05:15.677Z\",\"coreid\":\"54ff72066678574949480567\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:16.394Z\",\"content\":{\"event\":\"status\",\"data\":100001105,\"published_at\":\"2015-04-17T23:05:16.333Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d1
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:19.158Z\",\"content\":{\"event\":\"status\",\"data\":\"OFF\",\"published_at\":\"2015-04-17T23:05:19.096Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
^C
pc@raptor:~/workspaceArduino/sparktest$
pc@raptor:~/workspaceArduino/sparktest$
Unplugging the spark core here, I still see messages coming from dweet.io:
pc@raptor:~/workspaceArduino/sparktest$
pc@raptor:~/workspaceArduino/sparktest$ curl -i https://dweet.io/listen/for/dweets/from/wqDweetTest1
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 17 Apr 2015 23:05:45 GMT
Connection: keep-alive
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:45.830Z\",\"content\":{\"event\":\"status\",\"data\":100001202,\"published_at\":\"2015-04-17T23:05:45.768Z\",\"coreid\":\"54ff72066678574949480567\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:46.438Z\",\"content\":{\"event\":\"status\",\"data\":100001105,\"published_at\":\"2015-04-17T23:05:46.380Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:53.438Z\",\"content\":{\"event\":\"status\",\"data\":100001111,\"published_at\":\"2015-04-17T23:05:53.370Z\",\"coreid\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}}"
d3
"{\"thing\":\"wqDweetTest1\",\"created\":\"2015-04-17T23:05:59.402Z\",\"content\":{\"event\":\"status\",\"data\":100101214,\"published_at\":\"2015-04-17T23:05:59.339Z\",\"coreid\":\"54ff6a066678574948530467\"}}"
^C
pc@raptor:~/workspaceArduino/sparktest$
pc@raptor:~/workspaceArduino/sparktest$
Next, I delete the webhook from the spark cloud and run the curl log again, this time nothing is coming from dweet.io. The curl command finally timed out:
pc@raptor:~/workspaceArduino/sparktest$
pc@raptor:~/workspaceArduino/sparktest$
pc@raptor:~/workspaceArduino/sparktest$ curl -i https://dweet.io/listen/for/dweets/from/wqDweetTest1
curl: (52) Empty reply from server
So I’m concerned that the spark cloud is sending unnecessary traffic down the pipe. Or did I do something wrong? Thanks for any help on this issue.
[Edit: BTW, I masked out my core id, and found that there were some messages with a different core id.]