These are chat archives for esp8266/Arduino

15th
Jul 2016
Stavros Korokithakis
@skorokithakis
Jul 15 2016 10:48
hey everyone
i have this code to connect to a wifi network:
void connectWifi() {
    Serial.println("connecting");
    if (WiFi.waitForConnectResult() == WL_CONNECTED) {
        return;
    }

    resetPins();
    WiFi.persistent(false);
    WiFi.mode(WIFI_STA);
    while (WiFi.waitForConnectResult() != WL_CONNECTED) {
        WiFi.begin(WIFI_SSID, WIFI_PASS);
        Serial.println("Connecting to wifi...");
    }

    Serial.print("Wifi connected, IP address: ");
    Serial.println(WiFi.localIP());
}
i run it in setup() and in loop(), but even in setup(), it never seems to return or ever get past waitForConnectResult(), even though it connects
changing the start of the code to this:
    Serial.println("connecting");
    if (WiFi.waitForConnectResult() == WL_CONNECTED) {
        Serial.println("connected");
        return;
    }
    Serial.println("not connected");
prints "connecting" and never prints anything else, even though it connects to mqtt. i don't understand it...
Stavros Korokithakis
@skorokithakis
Jul 15 2016 10:53
i'm thinking maybe the serial stops printing
although some of my code also stops working
Stavros Korokithakis
@skorokithakis
Jul 15 2016 11:08
yeah, it's definitely the wifi connection routine, it doesn't even print the ip address
Stavros Korokithakis
@skorokithakis
Jul 15 2016 11:22
okay, the problem is definitely Serial.println(WiFi.localIP()). Taking that line out makes everything work
Holger Lembke
@holgerlembke
Jul 15 2016 12:04
hmmmm.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:13
has anyone gotten HTTP OTA to work? i keep getting timeouts when downloading the file
Holger Lembke
@holgerlembke
Jul 15 2016 12:15
this while loop could end in an endless loop
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:15
yes, but it's not that, it's the WiFi.localIP() line
taking that out works
Holger Lembke
@holgerlembke
Jul 15 2016 12:16
side effect.
This message was deleted
This message was deleted
boolean WiFiLogin(String ssid, String pwd) {
  //WiFi.begin("xxxx", "yyyyy");
  WiFi.begin(ssid.c_str(), pwd.c_str());

  int i = 0;
  while (( i < 20 ) && (WiFi.status() != WL_CONNECTED)) {
    delay(750);
    i++;
  }

  // Connected?
  if ( (WiFi.status() == WL_CONNECTED)) {
    Serial.print("Verbindung mit ");
    Serial.print(ssid);
    Serial.print(" erfolgreich, IP: ");
    Serial.println(WiFi.localIP());

    return true;
  };
 return false;
}
and that works fine...
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:18
that's very odd
Holger Lembke
@holgerlembke
Jul 15 2016 12:18
so the usual situation.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:22
yep :smile:
@igrr, any idea why my HTTP OTA updater isn't working? i'm just using the example, but getting read timeouts, while just using the browser works fine (but the ESP is making the request). do i need to use rebootOnUpdate somewhere? it's not in the examples, but it's in the .h file
Martin Ayotte
@martinayotte
Jul 15 2016 12:24
Serial.println(WiFi.localIP()) should be Serial.println(WiFi.localIP().toString())
Holger Lembke
@holgerlembke
Jul 15 2016 12:25
than a lot of examples must be fixed....
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:25
@martinayotte wouldn't that fail to compile?
i mean the way i used it
Martin Ayotte
@martinayotte
Jul 15 2016 12:26
Let me take a look if the first still valid
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:27
@martinayotte have you ever used HTTP OTA? it's failing in odd ways for me
Martin Ayotte
@martinayotte
Jul 15 2016 12:28
Ok ! it still valid because IPAddress derived from Printable class
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:28
ah, interesting
Martin Ayotte
@martinayotte
Jul 15 2016 12:29
@skorokithakis , No, I've never HTTP OTA, I'm using plain ArduinoOTA which works fine.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:30
@martinayotte yeah, plain OTA works for me too, but i plan to deploy 4-5 devices and this seems like a better way than updating each one
i was thinking of writing a simple HTTP server in Rust that would check the current directory for files named <fwname>-<version>.bin and serve them if the ESPs were out of date
so you could just drop the .bin in there, reboot your devices and they'd all be updated
Martin Ayotte
@martinayotte
Jul 15 2016 12:31
Clever !
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:31
not if i can't get OTA to work :(
Martin Ayotte
@martinayotte
Jul 15 2016 12:32
Of course ... what is that timeout issue ? is it when trying to connect to server ?
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:34
@martinayotte no, it connects properly and sends the headers, i see the log line on the server, but .update() never returns while trying to download the firmware
    Serial.println("Looking for an OTA update...");
    t_httpUpdate_return ret = ESPhttpUpdate.update("http://192.168.10.3:8000/firmware.bin", "100");
    Serial.println("returned");
never prints returned
let me fire up wireshark
Martin Ayotte
@martinayotte
Jul 15 2016 12:37
Looking at the lib, there are plenty of traces, you should turn On Debug mode to get details.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:39
how can i do that?
it looks like it can never manage to download the 400 kb firmware
Holger Lembke
@holgerlembke
Jul 15 2016 12:41
F10->Tools->Debug port+level
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:41
wireshark keeps showing TCP retransmissions
@holgerlembke i'm running platformio :/
Holger Lembke
@holgerlembke
Jul 15 2016 12:41
igit.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:42
hmm?
yeah, the packets are never reaching the destination. tcp window full/retransmit/out-of-order
could it be that the ESP is not sending ACKs?
hmm, i'm not very familiar with TCP, but the problem is definitely that the connection gets screwed up while downloading
Martin Ayotte
@martinayotte
Jul 15 2016 12:43
internally, the lib is simply doing an http.GET(), so traces should reveal where is the issue.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:44
@martinayotte do you know how i can trace with platformio?
Martin Ayotte
@martinayotte
Jul 15 2016 12:45
add some define to Makefile , -DDEBUG_ESP_PORT=Serial and also -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:45
let me try that, thanks
Stavros Korokithakis
@skorokithakis
Jul 15 2016 12:53
no, i can't get traces enabled :(
bah
let me try another ESP
no, a second ESP does the same thing...
Stavros Korokithakis
@skorokithakis
Jul 15 2016 13:02
and i can't enable traces... never mind, i'll use arduinoota
Martin Ayotte
@martinayotte
Jul 15 2016 13:04
I must admit that I don't known plateformio internals, but it should be possible to enable debug somehow.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 13:05
i just added those flags to the compiler, but they didn't work :/
maybe HTTP OTA doesn't work on a lan? i'm not sure
Martin Ayotte
@martinayotte
Jul 15 2016 13:06
HTTP OTA rely on HttpClient, so it should not matter if it is STA or AP
Stavros Korokithakis
@skorokithakis
Jul 15 2016 13:06
hm, right
Martin Ayotte
@martinayotte
Jul 15 2016 13:07
When you added flags, did it recompile all the libs ? if not you need to clean previous objs
Stavros Korokithakis
@skorokithakis
Jul 15 2016 13:07
oh, i didn't :(
damn, and i deleted all my code now
i will try again later
Martin Ayotte
@martinayotte
Jul 15 2016 13:08
:-( always keep backups ...
Stavros Korokithakis
@skorokithakis
Jul 15 2016 13:22
i didn't think i'd need it, since it didn't work
it was just the example, i'll add it again
Mehrdad K
@mkeyno
Jul 15 2016 13:40
can we use only voltage divider to connect I2c of Arduino & ESP or we should use part like 2N2222 , BSS138 ,2N7000
Martin Ayotte
@martinayotte
Jul 15 2016 13:44
I2C is bidirectional, so voltage divider can't be used here. you need something like : http://www.hobbytronics.co.uk/image/data/tutorial/mosfet_level_converter.jpg
Stavros Korokithakis
@skorokithakis
Jul 15 2016 14:01
@martinayotte aaand i tried again and now it works
yay heisenbugs
Mehrdad K
@mkeyno
Jul 15 2016 14:27
thanks @martinayotte , beside the mosfet option do you know any transistor solution
Martin Ayotte
@martinayotte
Jul 15 2016 14:41
Because of bi-directionality, I doubt a transistor solution exist.
Holger Lembke
@holgerlembke
Jul 15 2016 15:28
level shifters are quite cheap on ebay....
331578267071 four channel, $1.30 or so.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 15:39
@holgerlembke yeah, but waiting a month is expensive :P
Martin Ayotte
@martinayotte
Jul 15 2016 15:43
@skorokithakis , the link you provide is not for bi-directional I2C, they are for RS232.
Stavros Korokithakis
@skorokithakis
Jul 15 2016 15:43
oh, that's true, sorry
i thought you guys were talking about serial
Holger Lembke
@holgerlembke
Jul 15 2016 15:44
@skorokithakis i tend to do impulse buys... just get 6 or so and store them... i'm a perfect example that mankind evolved from hunters and collectors
Stavros Korokithakis
@skorokithakis
Jul 15 2016 15:45
@holgerlembke haha, yeah, i do the same, except the problem is that i'm usually only aware of things I need after i need them :)
Holger Lembke
@holgerlembke
Jul 15 2016 15:45
or aware that i already have them after I bought some more...
Martin Ayotte
@martinayotte
Jul 15 2016 15:49
:-)
Stavros Korokithakis
@skorokithakis
Jul 15 2016 15:51
haha, yes
Holger Lembke
@holgerlembke
Jul 15 2016 16:52
is there any accepted date/time-handling lib? (not ntp, but calculation)
Martin Ayotte
@martinayotte
Jul 15 2016 17:35
I'm using this lib too
Holger Lembke
@holgerlembke
Jul 15 2016 18:23
so thats 2:0 and a win.
Holger Lembke
@holgerlembke
Jul 15 2016 19:53
that lib misses daylightsaving....
Clemens Kirchgatterer
@everslick
Jul 15 2016 20:21
for proper daylight saving you'd need zoneinfo support
Holger Lembke
@holgerlembke
Jul 15 2016 21:04
as far as I see, it is even more complex than simple time zones... but anyway, I made a proposal for an implementation...