1

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.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Tobi
  • 13
  • 1
  • 1
  • 3
  • how are you showing the server's response? 13k might be too much for ram, depending on what else is running on the ESP... Also, you can use the ESP8266HTTPClient examples instead of the nasty manual request packet building. – dandavis Jun 06 '17 at 13:10

1 Answers1

1

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 ...
gre_gor
  • 6,669
  • 9
  • 47
  • 52