Skip to main content

I am HTTP Postingposting a data to this web apiAPI https://morning-cliffs-85779.herokuapp.com/api/users from aan arduinoArduino connected to esp8226. I am using the wifiesp library to HTTP_POST a data.

The REST apisAPIs are hosted in Heroku.

when isWhen I post it the arduinoArduino gives the response

Connected to server [WiFiEsp] Data packet send error (2) [WiFiEsp] Failed to write to socket 3 [WiFiEsp] Disconnecting 3

Connected to server
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting 3

and herokuthe Heroku server gives the response

at=error code=H13 desc="Connection closed without response"

at=error code=H13 desc="Connection closed without response"

Below is the arduinoArduino code:

`if  if (client.connect(server, 80)) {
    Serial.println("Connected to server");
    // Make a HTTP request
    String content = "id=5bc58842bdfea0153bb27214&volt=7";
    client.println("POST /api/users HTTP/1.1");
    client.println("Host: morning-cliffs-85779.herokuapp.com:80");// ("Host": host:port)
    client.println("Accept: */*");
    client.println("Content-Length: " + content.length());
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
    client.println(content);
  }

}`

This is the node express apiNode Express API:

`appapp.post('/api/users', function (req, res) {

console.log('here');

if (req.body.id) {
    DevReading.findByIdAndUpdate(req.body.id, {
        volt: req.body.volt
    }, function (err, reading) {
        if (err) throw err;

        res.send('Update Success');
    });
}

else {

var newDevReading = DevReading ({
    deviceName: 'test',
    volt: req.body.volt
});

newDevReading.save(function (err) {
    if (err) throw err;
    res.send('Reading Post Success');
});
}

});`;

I am HTTP Posting a data to web api https://morning-cliffs-85779.herokuapp.com/api/users from a arduino connected to esp8226. I am using wifiesp library to HTTP_POST a data.

The REST apis are hosted in Heroku

when is post it the arduino gives response

Connected to server [WiFiEsp] Data packet send error (2) [WiFiEsp] Failed to write to socket 3 [WiFiEsp] Disconnecting 3

and heroku server gives response

at=error code=H13 desc="Connection closed without response"

Below is the arduino code

`if (client.connect(server, 80)) {
  Serial.println("Connected to server");
// Make a HTTP request
String content = "id=5bc58842bdfea0153bb27214&volt=7";
client.println("POST /api/users HTTP/1.1");
client.println("Host: morning-cliffs-85779.herokuapp.com:80");// ("Host": host:port)
client.println("Accept: */*");
client.println("Content-Length: " + content.length());
client.println("Content-Type: application/x-www-form-urlencoded");
client.println();
client.println(content);

}`

This is the node express api

`app.post('/api/users', function (req, res) {

console.log('here');

if (req.body.id) {
    DevReading.findByIdAndUpdate(req.body.id, {
        volt: req.body.volt
    }, function (err, reading) {
        if (err) throw err;

        res.send('Update Success');
    });
}

else {

var newDevReading = DevReading ({
    deviceName: 'test',
    volt: req.body.volt
});

newDevReading.save(function (err) {
    if (err) throw err;
    res.send('Reading Post Success');
});
}

});`

I am HTTP posting a data to this web API https://morning-cliffs-85779.herokuapp.com/api/users from an Arduino connected to esp8226. I am using the wifiesp library to HTTP_POST data.

The REST APIs are hosted in Heroku.

When I post it the Arduino gives the response

Connected to server
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting 3

and the Heroku server gives the response

at=error code=H13 desc="Connection closed without response"

Below is the Arduino code:

  if (client.connect(server, 80)) {
    Serial.println("Connected to server");
    // Make a HTTP request
    String content = "id=5bc58842bdfea0153bb27214&volt=7";
    client.println("POST /api/users HTTP/1.1");
    client.println("Host: morning-cliffs-85779.herokuapp.com:80");// ("Host": host:port)
    client.println("Accept: */*");
    client.println("Content-Length: " + content.length());
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
    client.println(content);
  }

This is the Node Express API:

app.post('/api/users', function (req, res) {

console.log('here');

if (req.body.id) {
    DevReading.findByIdAndUpdate(req.body.id, {
        volt: req.body.volt
    }, function (err, reading) {
        if (err) throw err;

        res.send('Update Success');
    });
}

else {

var newDevReading = DevReading ({
    deviceName: 'test',
    volt: req.body.volt
});

newDevReading.save(function (err) {
    if (err) throw err;
    res.send('Reading Post Success');
});
}

});
Source Link

How to HTTP post a data to Node express API from a Arduino esp8226?

I am HTTP Posting a data to web api https://morning-cliffs-85779.herokuapp.com/api/users from a arduino connected to esp8226. I am using wifiesp library to HTTP_POST a data.

The REST apis are hosted in Heroku

when is post it the arduino gives response

Connected to server [WiFiEsp] Data packet send error (2) [WiFiEsp] Failed to write to socket 3 [WiFiEsp] Disconnecting 3

and heroku server gives response

at=error code=H13 desc="Connection closed without response"

Below is the arduino code

`if (client.connect(server, 80)) {
  Serial.println("Connected to server");
// Make a HTTP request
String content = "id=5bc58842bdfea0153bb27214&volt=7";
client.println("POST /api/users HTTP/1.1");
client.println("Host: morning-cliffs-85779.herokuapp.com:80");// ("Host": host:port)
client.println("Accept: */*");
client.println("Content-Length: " + content.length());
client.println("Content-Type: application/x-www-form-urlencoded");
client.println();
client.println(content);

}`

This is the node express api

`app.post('/api/users', function (req, res) {

console.log('here');

if (req.body.id) {
    DevReading.findByIdAndUpdate(req.body.id, {
        volt: req.body.volt
    }, function (err, reading) {
        if (err) throw err;

        res.send('Update Success');
    });
}

else {

var newDevReading = DevReading ({
    deviceName: 'test',
    volt: req.body.volt
});

newDevReading.save(function (err) {
    if (err) throw err;
    res.send('Reading Post Success');
});
}

});`