Skip to content

OTA Update with node js server #5302

Closed
Closed
@Zeni241

Description

@Zeni241

I am trying to implement OTA update from my Node Js server behind NGINX. I have this code in my sketch. (I am using NodeMCU 1.0 (ESP 12E) ).

void updater(){
  if ((WiFi.status() == WL_CONNECTED)) {
Serial.setDebugOutput(true);
   // t_httpUpdate_return ret = ESPhttpUpdate.update("http://server/file.bin");
    t_httpUpdate_return  ret = ESPhttpUpdate.update("mydomain.com",80,"/updater","v1");

    switch (ret) {
      case HTTP_UPDATE_FAILED:
        Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
        break;

      case HTTP_UPDATE_NO_UPDATES:
        Serial.println("HTTP_UPDATE_NO_UPDATES");
        break;

      case HTTP_UPDATE_OK:
        Serial.println("HTTP_UPDATE_OK");
        break;
    }
    delay(20000);
  }

My code in nodejs is:

app.post("/updater", function (req, res) {
    var h = req.headers;
    console.log(h["ESP8266 - version"]);
    console.log(h["ESP8266-mode"]);
    console.log(h["ESP8266-sketch-size"]);
//    res.send(req);
  //  return req;
});

First thing I want to assure that my request from my NodeMCU 1.0 (ESP 12E) is reaching the right address on the server. But I don’t get any console output.

The listing in Serial Monitor is as bellow:


[HTTP-Client][begin] host: mydomain.com port: 80 uri: /updater
[HTTP-Client] connected to mydomain.com:80
[HTTP-Client] connected to mydomain.com:80
17:40:47.239 -> [HTTP-Client] sending request header
17:40:47.239 -> -----
17:40:47.239 -> GET /updater HTTP/1.0
17:40:47.239 -> Host: mydomain.com
17:40:47.239 -> User-Agent: ESP8266-http-Update
17:40:47.239 -> Connection: close
17:40:47.239 -> x-ESP8266-STA-MAC: 84:F3:EB:B7:4E:8C
17:40:47.275 -> x-ESP8266-AP-MAC: 86:F3:EB:B7:4E:8C
17:40:47.275 -> x-ESP8266-free-space: 2830336
17:40:47.275 -> x-ESP8266-sketch-size: 314816
17:40:47.275 -> x-ESP8266-sketch-md5: 40f23fadc6d4efcbb22d68f7fcc9e409
17:40:47.275 -> x-ESP8266-chip-size: 4194304
17:40:47.275 -> x-ESP8266-sdk-version: 2.2.1(cfd48f3)
17:40:47.275 -> x-ESP8266-mode: sketch
17:40:47.275 -> x-ESP8266-version: v1
17:40:47.275 -> 
17:40:47.275 -> -----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 301 Moved Permanently'
17:40:49.091 -> [HTTP-Client][handleHeaderResponse] RX: 'Server: nginx/1.14.0 (Ubuntu)'
17:40:49.091 -> [HTTP-Client][handleHeaderResponse] RX: 'Date: Thu, 01 Nov 2018 12:40:49 GMT'
17:40:49.091 -> [HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/html'
17:40:49.091 -> [HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 194'
17:40:49.126 -> [HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
17:40:49.126 -> [HTTP-Client][handleHeaderResponse] RX: 'Location: https://mydomain.com/updater'
17:40:49.126 -> [HTTP-Client][handleHeaderResponse] RX: ''
17:40:49.126 -> [HTTP-Client][handleHeaderResponse] code: 301
17:40:49.126 -> [HTTP-Client][handleHeaderResponse] size: 194
17:40:49.126 -> [HTTP-Client][end] still data in buffer (194), clean up.
17:40:49.126 -> [HTTP-Client][end] tcp stop
17:40:49.126 -> HTTP_UPDATE_FAILD Error (-104): Wrong HTTP Code

Can someone please guide me what I am doing wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions