These are chat archives for esp8266/Arduino

7th
Apr 2016
Stavros Korokithakis
@skorokithakis
Apr 07 2016 00:29
turns out the tx/rx connections weren't secure enough and data was getting corrupted
is there a way to parse a string like "10 20 30" to ints easily?
Michael Miller
@Makuna
Apr 07 2016 00:58
atoi() three times?
Stavros Korokithakis
@skorokithakis
Apr 07 2016 01:11
that would require me to also know where to split the string, though
i'm looking for something like sscanf, but that doesn't seem to exist
i see it in a branch @igrr wrote, but it doesn't seem to be merged
Michael Miller
@Makuna
Apr 07 2016 01:19
what about strtok
Stavros Korokithakis
@skorokithakis
Apr 07 2016 01:23
aha! that's what i need, thanks!
ugh, why is everything in C so cumbersome...
Stavros Korokithakis
@skorokithakis
Apr 07 2016 01:35
can anyone tell me why this strtok code leads to an infinite loop? https://www.pastery.net/ydthje/
Martin Ayotte
@martinayotte
Apr 07 2016 01:51
You could try to use sscanf() to do the parsing, I've used it under STM32, but I don't if used under ESP will bring additional gcc libs
Oupps ! I've already figured out that you've already figured out that libcreplacement didn't provide it ... But maybe some tiny replacement could be added to libcreplacement
Stavros Korokithakis
@skorokithakis
Apr 07 2016 01:58
yes, but i don't know how :/
i hate having to spend one hour to do something so simple
i used strtok as above and it just hangs in an infinite loop
Michael Miller
@Makuna
Apr 07 2016 01:59
could strtok be used in the in mqttPublish? try strtok_r, strtok state can be reset if someone you don't know calls it.
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:00
hmm, this takes different arguments
i can't even find documentation on this :(
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:04
thanks, that was a bit too confusing, but this is clearer: https://stackoverflow.com/questions/15961253/c-correct-usage-of-strtok-r
yep, looks like that was the problem
it's no longer infinitely looping now
thanks
Michael Miller
@Makuna
Apr 07 2016 02:05
char* strtok(char* s, const char* delim) {
    static char* last;

    return (strtok_r(s, delim, &last));
}
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:06
oh, will that work? what does static do?
Michael Miller
@Makuna
Apr 07 2016 02:31
that is the implementation of strtok, and why its a problem to use, as it stores a value between calls (that's what static does, it states, make the variable live longer than the scope) so that if someone else calls it, it resets the static that you were calling.
it also shows how you can use strtok_r() where ever you used strtok before, just provide your own locally scoped (but still always within the scope of the multiple calls) variable to the last param.
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:36
i see, that clarifies everything, thank you
so it looks like something else was indeed calling it, and it must have been something in mqttPublish, because it was sending the things in the preamble
mqttPublish concatenates some String objects, i think that was what was calling it
also, another interesting observation: analogWrite(2, 1000); digitalWrite(2, 0); doesn't reset the pin to 0
Michael Miller
@Makuna
Apr 07 2016 02:37
which is scary, as do they protect themselves from someone doing it to them.
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:37
it only resets it for an instant
@Makuna yeah, i don't think they do :/
Michael Miller
@Makuna
Apr 07 2016 02:39
there is a whole series of these state storing C standard functions that SHOULD BE AVOIDED, as there is always the better alternative that doesn't.
Stavros Korokithakis
@skorokithakis
Apr 07 2016 02:42
it's unfortunate that they don't do the right thing by default :/
Me No Dev
@me-no-dev
Apr 07 2016 07:43
also, another interesting observation: analogWrite(2, 1000); digitalWrite(2, 0); doesn't reset the pin to 0
analogWrite(2, 0) will do it
pwm is software so digitalWrite will not do much
andig
@andig
Apr 07 2016 17:13
hi guys, has anybody made the experience that the addition of the httpclient comes at a cost of ~6k ram?
is that the topic that igrr recently mentioned might be addressed by leaving https handling out with some linker changes?