Open filipecavalc opened 6 years ago
Just found the find3 project and of course I had to install some ESP's for tracking! But I'm having the same issue as Filip.
I'm using NodeMCU ESP8266 (https://www.amazon.com/HiLetgo-Internet-Development-Wireless-Micropython/dp/B010O1G1ES)
I've tried compiling it using the same board as filip, and a bunch of others, including the "Generic ESP8266" board.
As you can see in the code, only WifiCluentSecure.h and Wifi.h is recognized, I've googled a bit and others have had this issue with winXP, but I'm on win10 and I've tried reinstalling the ESP8266 board and also the whole arduino IDE.
I've only done a couple of "copy/paste" projects with ESP's so I'm hoping someone will find this and possibly have a good suggestion on what to do
NODEMCU ESP8266 here to, i make some changes and add some libraries for ESP8266, and now i am getting just One error report.
ESP8266WiFiMulti wifiMulti;
const char ssid = "xxx"; const char password = "xxx";
// Uncomment to set to learn mode
const char host = "cloud.internalpositioning.com"; const char ntpServer = "pool.ntp.org";
//#define DEBUG 1
String chipIdStr;
void setup() { Serial.begin(115200); delay(1000);
chipIdStr = String((uint32_t)(ESP.getChipId()>>16)); Serial.print("[ INFO ]\tChipID is: "); Serial.println(chipIdStr);
wifiMulti.addAP(ssid, password);
Serial.println("[ INFO ]\tConnecting to WiFi.."); if (wifiMulti.run() == WL_CONNECTED) { Serial.println("[ INFO ]\tWiFi connection established."); Serial.print("[ INFO ]\tIP address: "); Serial.println(WiFi.localIP()); configTime(0, 0, ntpServer); } }
unsigned long long getUnixTime() { time_t now; struct tm timeinfo; if (!getLocalTime(&timeinfo)) { Serial.println("[ ERROR ]\tFailed to obtain time via NTP. Retrying."); getUnixTime(); } else { Serial.println("[ INFO ]\tSuccessfully obtained time via NTP."); } time(&now); unsigned long long uTime = (uintmax_t)now; return uTime * 1000UL; }
void SubmitWiFi(void) { String request; uint64_t chipid;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); root["d"] = chipIdStr; root["f"] = GROUP_NAME; JsonObject& data = root.createNestedObject("s");
Serial.println("[ INFO ]\tWiFi scan starting.."); int n = WiFi.scanNetworks(false, true); Serial.println("[ INFO ]\tWiFi Scan finished."); if (n == 0) { Serial.println("[ ERROR ]\tNo networks found"); } else { Serial.print("[ INFO ]\t"); Serial.print(n); Serial.println(" WiFi networks found."); JsonObject& wifi_network = data.createNestedObject("wifi"); for (int i = 0; i < n; ++i) { wifi_network[WiFi.BSSIDstr(i)] = WiFi.RSSI(i); }
#ifdef MODE_LEARNING
root["l"] = LOCATION;
#endif
root["t"] = getUnixTime();
root.printTo(request);
#ifdef DEBUG
Serial.println(request);
#endif
WiFiClientSecure client;
const int httpsPort = 443;
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
}
// We now create a URI for the request
String url = "/data";
Serial.print("[ INFO ]\tRequesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: " + request.length() + "\r\n\r\n" +
request +
"\r\n\r\n"
);
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println("[ ERROR ]\tHTTP Client Timeout !");
client.stop();
return;
}
}
// Check HTTP status
char status[60] = {0};
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0) {
Serial.print(F("[ ERROR ]\tUnexpected Response: "));
Serial.println(status);
return;
}
else
{
Serial.println(F("[ INFO ]\tGot a 200 OK."));
}
char endOfHeaders[] = "\r\n\r\n"; if (!client.find(endOfHeaders)) { Serial.println(F("[ ERROR ]\t Invalid Response")); return; } else { Serial.println("[ INFO ]\tLooks like a valid response."); }
Serial.println("[ INFO ]\tClosing connection."); Serial.println("=============================================================");
} }
void loop() { SubmitWiFi(); }
I copied your code and just tried to uncomment everything with regarding the time, not sure what i will brake though. But I got it to compile and load it into my ESP, code seems to be running but it doesn't connect to my wifi
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld
[ INFO ] ChipID is: 22
[ INFO ] Connecting to WiFi..
[ INFO ] WiFi scan starting..
[ INFO ] WiFi Scan finished.
[ INFO ] -1 WiFi networks found.
connection failed
[ INFO ] Requesting URL: /data
Soft WDT reset
ctx: cont
sp: 3fff04d0 end: 3fff0770 offset: 01b0
>>>stack>>>
3fff0680: 3ffe8568 3fff06cc 3ffef688 40202e32
3fff0690: 00000000 00000000 00000000 fffffffe
3fff06a0: 000000fe 3ffef42c 00000000 40203348
3fff06b0: 00000000 00000001 3ffef420 401004d8
3fff06c0: 3ffe8cc0 0000000a 3ffe8304 401071d8
3fff06d0: 00000000 00003a98 3ffe8ba1 00000000
3fff06e0: 00000000 00000000 00000000 401070f0
3fff06f0: 3fffdad0 3fff143c 00000200 00000000
3fff0700: 00000000 00000000 3fff1424 0000000f
3fff0710: 00000005 3fff154c 0000003f 00000039
3fff0720: ffffffff 3fff148c 3ffef688 3ffef748
3fff0730: 3fffdad0 3ffef420 3ffef688 3ffef748
3fff0740: 3fffdad0 00000000 3ffef740 40202f04
3fff0750: feefeffe 00000000 3ffef740 40205c50
3fff0760: feefeffe feefeffe 3ffef750 40100710
<<<stack<<<
same here, i have a ESP32 in home i will test later, but this code need some treatment to run in ESP8266 no doubt
Maybe i will try do it from scratch for ESP8266, i send here if i do.
The "connection failed" comes from these lines, I edited them and added the https just to track where the error comes from.
WiFiClientSecure client; const int httpsPort = 443; if (!client.connect(host, httpsPort)) { Serial.println("https connection failed"); }
Not sure if it needs https on the find3 server, I'm using regular http for it right now, and specified the host as:
"const char* host = "192.168.1.5:8005";"
[ INFO ] ChipID is: 22 [ INFO ] Connecting to WiFi.. [ INFO ] WiFi scan starting.. [ INFO ] WiFi Scan finished. [ INFO ] -1 WiFi networks found. https connection failed [ INFO ] Requesting URL: /data
my is crashing before requesting URL:/data
I will upload an updated version in the upcoming days. I have fixed this issue in the last release by adding yield() to the main and loop and by adding ifdefs for ESP32 and 8266. Stay tuned! :)
Aah nice to hear!
I also tired @filipecavalc code and have the same result. Any news on the updated version? I'm a big fan of the pervious Find and can't wait to try the 3.0.
so i got myself a nodeMCU esp32 and tried to upload the code.
first i was getting WiFi.h not found, then i switch it around with
@Abulrock Please see https://github.com/DatanoiseTV/esp-find3-client/blob/master/esp-find3-client.ino#L38
I will update the code asap. I was pretty busy, but I will try to do it this week.
no worries and thank you very much for the hard work. i tried the new code with ESP32 and ESP12E. ESP32: it was not connecting at first, i added WiFi.mode(WIFI_STA); and it worked once, but once i uploaded the code again (to learn) it didnt. i think it was timing out before being able to connect to my wifi. so i removed wifiMulti and just used WiFi.begin with While. its connected now and uploading learning, i think the ones learned using the phone are not matching. However; i still have the issue with file size 130% if i enable BT. as for ESP12E: it uploaded fine but it keeps crashing when "requesting URL". i hope this helps, i will continue to run some test and let you know if i find anything else.
thanks again
i hope you dont mind but i modified your code to work on ESP12E (Tested) but i would assume it will work the same on esp8266.
You need the library for (NTPClient.h) because i changed the way to get time. (you might need to add the timezone difference). deepsleep is also changed, if not needed while Learning just comment out, (it will put eps to sleep for 20 seconds).
if multiWifi is not needed it can be removed, right now its commented out. when i use it, it times out before connecting, not sure its an issue with my router.
ESP8266WiFiMulti wifiMulti;
WiFiUDP ntpUDP;
// You can specify the time server pool and the offset (in seconds, can be // changed later with setTimeOffset() ). Additionaly you can specify the // update interval (in milliseconds, can be changed using setUpdateInterval() ). NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 60000);
const char ssid = "WIFI_SSID"; const char password = "WIFI_PASS";
// Uncomment to set to learn mode //#define MODE_LEARNING 1
const char host = "cloud.internalpositioning.com"; const char ntpServer = "pool.ntp.org";
//#define DEBUG 1
String chipIdStr;
void setup() { Serial.begin(115200); delay(1000); chipIdStr = String(ESP.getChipId());
Serial.print("[ INFO ]\tChipID is: ");
Serial.println(chipIdStr);
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password);
// Wait for the connection, flashing the LED while we wait
while (WiFi.status() != WL_CONNECTED) { delay(200); Serial.print("."); } Serial.println("");
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
timeClient.begin();
/* wifiMulti.addAP(ssid, password);
Serial.println("[ INFO ]\tConnecting to WiFi.."); if (wifiMulti.run() == WL_CONNECTED) { Serial.println("[ INFO ]\tWiFi connection established."); Serial.print("[ INFO ]\tIP address: "); Serial.println(WiFi.localIP()); configTime(0, 0, ntpServer); } */ }
unsigned long long getUnixTime() { timeClient.update(); unsigned long long epoch = timeClient.getEpochTime(); return epoch * 1000UL; }
void SubmitWiFi(void) { String request; uint64_t chipid;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); root["d"] = chipIdStr; root["f"] = GROUP_NAME; root["t"] = getUnixTime(); JsonObject& data = root.createNestedObject("s");
Serial.println("[ INFO ]\tWiFi scan starting.."); int n = WiFi.scanNetworks(false, true); Serial.println("[ INFO ]\tWiFi Scan finished."); if (n == 0) { Serial.println("[ ERROR ]\tNo networks found"); } else { Serial.print("[ INFO ]\t"); Serial.print(n); Serial.println(" WiFi networks found."); JsonObject& wifi_network = data.createNestedObject("wifi"); for (int i = 0; i < n; ++i) { wifi_network[WiFi.BSSIDstr(i)] = WiFi.RSSI(i); }
#ifdef MODE_LEARNING
root["l"] = LOCATION;
#endif
root.printTo(request);
#ifdef DEBUG
Serial.println(request);
#endif
WiFiClientSecure client;
const int httpsPort = 443;
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
}
// We now create a URI for the request
String url = "/data";
Serial.print("[ INFO ]\tRequesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: " + request.length() + "\r\n\r\n" +
request +
"\r\n\r\n"
);
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 2500) {
Serial.println("[ ERROR ]\tHTTP Client Timeout !");
client.stop();
SubmitWiFi();
}
}
// Check HTTP status
char status[60] = {0};
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0) {
Serial.print(F("[ ERROR ]\tUnexpected Response: "));
Serial.println(status);
return;
}
else
{
Serial.println(F("[ INFO ]\tGot a 200 OK."));
}
char endOfHeaders[] = "\r\n\r\n"; if (!client.find(endOfHeaders)) { Serial.println(F("[ ERROR ]\t Invalid Response")); return; } else { Serial.println("[ INFO ]\tLooks like a valid response."); }
Serial.println("[ INFO ]\tClosing connection."); Serial.println("=============================================================");
ESP.deepSleep(20e6); // 20e6 is 20 microseconds
} }
void loop() { SubmitWiFi(); yield();
}
EDIT: it crashes every now and then now sure why, but it resets.
hi, I tried to compile the source of the git, NTP problem: °. I tried to compile your code, with some changes, on ESP32 and with the cloud it works perfectly. thank you!!! (NTPClient)
demand how I communicate with my server: 192.168.1.2:8005 .... ask for SSL and nothing.
someone knows how to add code for the BLE.
in advance, thank you for your kind attention.
`#include
WiFiMulti wifiMulti;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 60000);
const char ssid = "xxx"; const char password = "xxx";
// Uncomment to set to learn mode //#define MODE_LEARNING 1
const char host = "cloud.internalpositioning.com"; const char ntpServer = "pool.ntp.org";
//#define DEBUG 1
String chipIdStr;
void setup() { Serial.begin(115200); delay(1000); chipIdStr = String((uint32_t)(ESP.getEfuseMac()>>16));
Serial.print("[ INFO ]\tChipID is: "); Serial.println(chipIdStr);
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password);
// Wait for the connection, flashing the LED while we wait
while (WiFi.status() != WL_CONNECTED) { delay(200); Serial.print("."); } Serial.println("");
Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); timeClient.begin();
wifiMulti.addAP(ssid, password);
Serial.println("[ INFO ]\tConnecting to WiFi.."); if (wifiMulti.run() == WL_CONNECTED) { Serial.println("[ INFO ]\tWiFi connection established."); Serial.print("[ INFO ]\tIP address: "); Serial.println(WiFi.localIP()); configTime(0, 0, ntpServer); }
}
unsigned long long getUnixTime() { timeClient.update(); unsigned long long epoch = timeClient.getEpochTime(); return epoch * 1000UL; }
void SubmitWiFi(void) { String request; uint64_t chipid;
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); root["d"] = chipIdStr; root["f"] = GROUP_NAME; root["t"] = getUnixTime(); JsonObject& data = root.createNestedObject("s");
Serial.println("[ INFO ]\tWiFi scan starting.."); int n = WiFi.scanNetworks(false, true); Serial.println("[ INFO ]\tWiFi Scan finished."); if (n == 0) { Serial.println("[ ERROR ]\tNo networks found"); } else { Serial.print("[ INFO ]\t"); Serial.print(n); Serial.println(" WiFi networks found."); JsonObject& wifi_network = data.createNestedObject("wifi"); for (int i = 0; i < n; ++i) { wifi_network[WiFi.BSSIDstr(i)] = WiFi.RSSI(i); }
root["l"] = LOCATION;
root.printTo(request);
Serial.println(request);
WiFiClientSecure client; const int httpsPort = 443; if (!client.connect(host, httpsPort)) { Serial.println("connection failed"); }
// We now create a URI for the request String url = "/data";
Serial.print("[ INFO ]\tRequesting URL: "); Serial.println(url);
// This will send the request to the server client.print(String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Content-Type: application/json\r\n" + "Content-Length: " + request.length() + "\r\n\r\n" + request + "\r\n\r\n" );
unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 2500) { Serial.println("[ ERROR ]\tHTTP Client Timeout !"); client.stop(); SubmitWiFi(); } }
// Check HTTP status char status[60] = {0}; client.readBytesUntil('\r', status, sizeof(status)); if (strcmp(status, "HTTP/1.1 200 OK") != 0) { Serial.print(F("[ ERROR ]\tUnexpected Response: ")); Serial.println(status); return; } else { Serial.println(F("[ INFO ]\tGot a 200 OK.")); } char endOfHeaders[] = "\r\n\r\n"; if (!client.find(endOfHeaders)) { Serial.println(F("[ ERROR ]\t Invalid Response")); return; } else { Serial.println("[ INFO ]\tLooks like a valid response."); }
Serial.println("[ INFO ]\tClosing connection."); Serial.println("=============================================================");
ESP.deepSleep(20e6); // 20e6 is 20 microseconds
} }
void loop() { SubmitWiFi(); yield();
}`