I am pretty new to programming (the ESP8266).
Right now I am putting code-pieces from different blogs together in order to receive(!) pushes (messages) from Pushbullet.
Sending already works great thanks to:
POST request on arduino with ESP8266 using WifiESP library
The cURL example from Pushbullet is:
curl --header 'Access-Token: <your_access_token_here>' \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Space Elevator, Mars Hyperloop, Space Model S (Model Space?)","title":"Space Travel Ideas","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
And the 'translation' to Arduino/ESP8266:
String request = String("POST ") + url +" HTTP/1.1\r\n" +
"Host: " + push_bullet_host + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: "+ body.length() +"\r\n" +
"Access-Token: "+ api_token +"\r\n\r\n" +
body;
secure_client.print(req);
So what I want to do now is requesting the latest messages from Pushbullet.
The example in cURL is:
curl --header 'Access-Token: <your_access_token_here>' \
--data-urlencode active="true" \
--data-urlencode modified_after="1.4e+09" \
--get \
https://api.pushbullet.com/v2/pushes
And my attempt to get it working is:
String request = String("GET ") + url +" HTTP/1.1\r\n" +
"Host: " + push_bullet_host + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"active=\"true\"\r\n" +
"modified_after=\"1496508764\"\r\n" +
"Access-Token: "+ api_token +"\r\n\r\n";
secure_client.print(req);
But all I receive is the following:
>>HTTP/1.1 200 OK>>
X-Ratelimit-Reset: 1496515364>>
Content-Type: application/json; charset=utf-8>>
X-Ratelimit-Limit: 16384>>
X-Ratelimit-Remaining: 16384>>
X-Cloud-Trace-Context: blablalba>>
Date: Sat, 03 Jun 2017 18:05:06 GMT>>
Server: Google Frontend>>
Content-Length: 13626>>
I really appreciate any idea or solution.
active="true"
and modified_after="1496508764"
are not valid headers.
You don't even want them in headers, since they are supposed to be query parameters.
You should append those parameters to the URL.
String request = String("GET ") + url +"?active=true&modified_after=1.4e%2B09 HTTP/1.1\r\n" +
"Host: " + push_bullet_host + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"Access-Token: "+ api_token +"\r\n\r\n";
You can see what exactly the curl
command sends and receives, if you run it the -v
or --verbose
option:
curl --header 'Access-Token: <your_access_token_here>' \
--data-urlencode active="true" \
--data-urlencode modified_after="1.4e+09" \
--get -v\
https://api.pushbullet.com/v2/pushes
With this you would see:
* ... TLS stuff ...
> GET /v2/pushes?active=true&modified_after=1.4e%2B09 HTTP/1.1
> Host: api.pushbullet.com
> User-Agent: curl/7.42.1
> Accept: */*
> Access-Token: <your_access_token_here>
>
< ... Response headers ...