Hello,
I am trying to do Over The Air updates to ESP8266 WeMoS D1R1 device. The example following code WORKS, proving the device, bin file, and host are all communicating. However, when i put the same function / call into my real application, the OTA fails with 'connection refused'. I'm going crazy trying to figure out why this fails.
The ESP8266WifiMulti is the obvious difference, but don't need this to connect to multiple wifi networks, and it shouldn't make a difference (in theory).
Guidance greatly received on what to look at, to debug !
THIS WORKS FINE (obviously substituting host URL and fingerprint key) !!!
/**
-
httpUpdate.ino
-
Created on: 27.11.2015
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
void setup() {
USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println("**** IMAGE 1");
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFiMulti.addAP("", "");
}
void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {
USE_SERIAL.println("Updating...");
t_httpUpdate_return ret = ESPhttpUpdate.update("Bitbucket");
USE_SERIAL.printf("\nret: %d\n",ret);
switch(ret) {
case HTTP_UPDATE_FAILED:
USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
USE_SERIAL.println("HTTP_UPDATE_OK");
break;
}
}
}
>:( >:( THIS DOES NOT WORK....ONLY PART OF THE CODE, BUT HOPEFULLY THE KEY BITS. The error is "connection refused".
#include <ESP8266WiFi.h>
#include "PubSubClient.h"
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <WiFiManager.h> //GitHub - tzapu/WiFiManager: ESP8266 WiFi Connection manager with web captive portal
....
WiFiClient wifiClient;
....
void callback(const MQTT::Publish& pub) {
Serial.println("MQTT Topic: " + pub.topic() + " MQTT Payload: " + pub.payload_string());
if (pub.payload_string() == "flash") {
WiFiClient client;
t_httpUpdate_return ret = ESPhttpUpdate.update(FirmwareURL, "", FingerPrint);
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", 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;
}
}