Particle Publish Event CURL not working

I use the following command:

curl https://api.particle.io/v1/devices/events -d "name=test_ event” -d "data=-1” -d “private=true” -d “ttl=60” -d access_token= 1931fe7…XXXXXXXX
{
“ok”: true
}curl: (6) Could not resolve host: 1931fe…XXXXXX

am I missing something?

I believe the problem is that you have a space between the = and the 1931fe…

1 Like

@rickkas7, thanks.

@rickkas7, I am having a problem passing data to my handler. I passed in data=1 as follows. But when I do serial print I am getting undefined for data or after converting char to float I am getting 0.00 instead of 1.

curl https://api.particle.io/v1/devices/events -d "name=hello_event” -d "data=1” -d “private=true” -d “ttl=60” -d access_token=193…XXXXXXXX…

Particle.subscribe(“hello_event”, helloHandler,MY_DEVICES);

void helloHandler(const char *event, const char *data){

float fr=atof(data);

Serial.println(fr);

}

return fr as 0.00 instead of 1 and return data as undefined when I do serial print data.

Maybe printing out the received const char* data first will give you a clue why atof() may not be able to convert.
And it would also help us to see what your raw data looks like and where that issue might come from.

try this

void helloHandler(const char *event, const char *data) {
  float fr=atof(data);

  Serial.printlnf("<%s> %.1f", data, fr);
}

The <> combo should also reveal if there are any non-printables like <CR> or <LF> embedded.

So post the output wrapped in a block of these

 ```text
 here your output
1 Like

I believe the problem is that two of your double quotes are the typographical kind. You need the normal straight kind on the command line.

"name=hello_event” -d "data=1” 
                 ^           ^  wrong quotes here
2 Likes

Good catch!
That’s one reason why using the proper way to provide text blocks in this forum can help finding such things.

When you wrap your command in a set of these

your text here



// or for CPP code
```cpp
// code here
it will look like this

curl https://api.particle.io/v1/devices/events -d "name=hello_event” -d "data=1” -d “private=true” -d “ttl=60” -d access_token=193…XXXXXXXX…

```cpp
Particle.subscribe("hello_event", helloHandler,MY_DEVICES);

void helloHandler(const char *event, const char *data){
  float fr=atof(data);
  Serial.println(fr);
}

Notice the code highliting - the closing double quote is not interpreted as such.
And printing out const char* data and const char* event should have revealed this too.
With above statement the event name would probably be hello_event” -d


More Forum Tips and Tricks

1 Like

@rickkas7 and @ScruffR, thanks. Yes, double quotes were the problems.

1 Like