Esp32/arduino post request error

I am trying to post some test data to emoncms, but no luck so far. Do any of you have working code for an esp32 or arduino post request? If yes can you share it, please? I am getting an “HTTP/1.1 302 Found” response.

here are the data from serial monitor and my code

WiFi connected
IP address:
connecting to
Requesting URL: /input/post.json?node=2&private_key=exxxxxxxxxxxxxxxxxx1b&json={temperature:1}
HTTP/1.1 302 Found
Date: Wed, 20 Jun 2018 16:44:44 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.25
Set-Cookie: PHPSESSID=av4f2o44ega1orqhgta4ikt8k4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 0
Connection: close

#include <WiFi.h>

const char* ssid     = "xxxxxxxxxxx";
const char* password = "pxxxxxxxxxxxxxo";

const char* host = "";
const char* nodeId   = "2";
const char* privateKey = "e3abxxxxxxxxxxxxxxxxx6ff1b";

void setup()

    //connecting to a WiFi network

    Serial.print("Connecting to ");

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {

    Serial.println("WiFi connected");
    Serial.println("IP address: ");

int value = 0;

void loop()

    Serial.print("connecting to ");

    WiFiClient client;  
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");

    String json = "{temperature:";
    json += value;
    json += "}";

    String url = "/input/post.json?node=";
    url += nodeId;
    url += "&private_key=";
    url += privateKey;
    url += "&json=";
    url += json;

    Serial.print("Requesting URL: ");

    // This will send the request to the server
    client.print(String("POST ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout > 5000) {
            Serial.println(">>> Client Timeout !");

    // Read all the lines of the reply from server and print them to Serial
    while(client.available()) {
        String line = client.readStringUntil('\r');

    Serial.println("closing connection");

Without getting too deep into what you’re doing, I don’t have an ESP32 set up right now, but here are a couple of things you might check:

  1. You are using POST but you seem to be sending the data in a GET query string with no POST payload. I’d suggest getting it working with GET to start, which is simpler. The documentation can be a little confusing because they use /input/post in a GET transaction. The post in the URI refers to the Emoncms action of posting data to the input rather than the HTTP POST protocol.

  2. I’ve never user &private_key= and don’t see that in the API documentation. &apikey= works.

  3. While there are variants of these formats that are not necessarily in the documentation, I don’t see /input/post/json. Maybe try something from the documentation like this:


This is the “json like” format, which isn’t actually Json because temperature isn’t enclosed in quotes. You can go with real Json (I recommend ArduinoJson) but the keyword should be &fulljson= in that case.

  1. Lastly, if you use HTTPclient, you can move up a level and send the headers and data without bothering with the nitty gritty of HTTP.

Good Luck.