Spark.publish constantly sending messages without my prompting

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.]

Just an off-the-shelf tip - which might not help, but alway fits :wink:

Get a bit more adventurous with your event names - status is soooo boring, that others might have used it as well :neutral_face:

Yeah, “status” is boring, but this is a TEST. If it had been a real emergency… :anguished:

Actually, I think I partially solved the problem. I added

"mydevices": true

into the webhook json file. This stopped the extraneous messages. I tried to add the actual “coreid” to the webhook file, but the spark cloud didn’t accept it. I also tried “deviceid” but that didn’t work either. Not sure if that makes any difference, but at least I don’t get anymore crap that I have to parse through. I wish the documentation was a little more thorough. Any insight into this matter would be appreciated.

1 Like

Sure thing mydevices is the dedicated way to have your own stay your own, but with a more unique event name, you may not have fallen into this in the first place :wink:

So as said - off-the-shelf try to be unique :smiley:

2 Likes

Point taken.

How about the coreid/deviceid key? Is that something that acutally works? How does one implement something like that?

Do you mean something like

    Spark.publish(Spark.deviceID(), "TEST");

I have no idea what that is, nor have I seen anything like that. I'm talking about one of webhook's standard options (http://docs.spark.io/webhooks/#webhook-options)

DEVICEID
Provide a full id of one of your devices, and the webhook will only respond to events from that device.

If I did everything correctly (and the documentation is ambiguous about this) you would put the key "deviceid" in your json file that you use to create the webhook. Unless I'm missing something, that's how the documentation explains it. I've tried to setup the deviceid, but it never got recognized, as the spark cloud's response shows:

pc@raptor:~/workspaceArduino/sparktest$ spark webhook create dweet1.json 
Using settings from the file dweet1.json
Sending webhook request  { uri: 'https://api.spark.io/v1/webhooks',
  method: 'POST',
  json: true,
  form: 
   { event: 'machineStat',
     url: 'https://dweet.io:443/dweet/for/wqDweetTest2',
     deviceid: undefined,
     access_token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     requestType: 'POST',
     headers: undefined,
     json: undefined,
     query: undefined,
     auth: undefined,
     mydevices: true } }
Successfully created webhook!
pc@raptor:~/workspaceArduino/sparktest$ 

Hey look, new event name! :smile: Don't anyone else use it now! :angry: :smile: :smile: :smile:

@aceperry, it is stated here of the purpose:

http://docs.spark.io/webhooks/#webhook-options-deviceid

Provide a full id of one of your devices, and the webhook will only respond to events from that device.

I tested on the fix i wrote: https://github.com/spark/spark-cli/pull/181 and it worked fine taing in the deviceid parameter.

Let’s hope it gets merged soon :wink:

1 Like

@kennethlimcp, thanks for the post. I looked over the patch you submitted and found that if you use the key “coreID”, it will setup the deviceid in your webhook, unlike the documentation which leads you to believe that the correct key is “deviceid”. I’m not sure what will happen with your patch, but the spark-cli in it’s current form will accept “coreID”.

dweet1.json

{
  "eventName": "machineStat",
  "url": "https://dweet.io:443/dweet/for/wqDweetTest2",
  "coreID": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "requestType": "POST",
  "mydevices": true
}

response to webhook creation, it worked!

pc@raptor:~/workspaceArduino/sparktest$ spark webhook delete 5531ab9816dfc40b73a8e97d
Successfully deleted webhook!
pc@raptor:~/workspaceArduino/sparktest$ spark webhook create dweet1.json 
Using settings from the file dweet1.json
Sending webhook request  { uri: 'https://api.spark.io/v1/webhooks',
  method: 'POST',
  json: true,
  form: 
   { event: 'machineStat',
     url: 'https://dweet.io:443/dweet/for/wqDweetTest2',
     deviceid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     access_token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     requestType: 'POST',
     headers: undefined,
     json: undefined,
     query: undefined,
     auth: undefined,
     mydevices: true } }
Successfully created webhook!
pc@raptor:~/workspaceArduino/sparktest$

*Magic numbers have been removed to protect the innocent. :smile:

And it works!

2 Likes

I will bring this up since the docs and current behavior is not matching

Used deviceID in my json file but i will check just to be sure

1 Like

I guess one problem is that you have to capitalize 'ID', which is completely unexpected and not at all documented. I don't care whether it should be deviceid/deviceID or coreid/coreID, as long as it is clearly documented. I'll use it, I just wish the documentation was correct. Hope this gets sorted out.

One thing that could use clarification is the difference between using the deviceid and the mydevices key for webhooks. I'd like to know why you would use one instead of the other. Other than that, webhooks are very cool stuff. :+1: