These are chat archives for esp8266/Arduino

10th
Mar 2016
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:14
Oh, right, haha, we’re in this one together.
Angus Gratton
@projectgus
Mar 10 2016 00:14
well, kind of :)
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:15
Well, I’m using the ESP’s SPI calls, yeah, I mean, it was pretty stable up to 2.0.0 of this project...
my gus’s, how arrogant is that, it;s yours, not mine.
I thought this WAS hardware SPI, am I mistaken?
Angus Gratton
@projectgus
Mar 10 2016 00:19
oh sorry, i didn't mean it that way. I just meant I haven't tried DMD2 on ESP8266 at all, so after a certain point you're on your own :)
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:19
I mean, I did wrap SoftDMD in a preprocessor if to disable it on the esp8266.
Angus Gratton
@projectgus
Mar 10 2016 00:20
ah, i mis-remembered that esp8266 support was only SoftDMD, not the other way around
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:20
I had it working pretty solid, I guess need to wait for servo to be fixed, it’s a tiny bit over me in terms of programming knowledge, but I usually do ok.
Ah, right, well, I’m def the person to ask lol
Angus Gratton
@projectgus
Mar 10 2016 00:20
but I don't really know
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:21
I’m gonna trying commenting some things out and maybe trying ticker instead, because it was actually working ok with a software timer too...
I’d like to keep it working with the latest and greatest if I can.
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:38
I’m going to release my schematics when I’ve fixed one hardware bug on the reset button, I’ve got a board that fits in the 5x5cm limit for DirtyPCBs with esp, power, ds1307, light sensor and power leads for the DMD.
Plugs straight in the back of the DMD, Wifi DMD!
Some through hole, some surface mount.
You get this board & cheapo FTDI plugs straight into a header for programming.
Angus Gratton
@projectgus
Mar 10 2016 00:38
nice!
Harrison Mclean
@h4rm0n1c
Mar 10 2016 00:39
I hope I can get it working well again, I’d be a shame to have to include a separate micro for the DMD, but If I have to, that’s what I’ll do.
Michael Miller
@Makuna
Mar 10 2016 00:53

@h4rm0n1c you stated you are waiting for servo fix, I think I have fix but I am remote without an esp to test with. If you edit servo.cpp and add the following two lines like this...

static void finISR(ServoTimerSequence timerId) ICACHE_RAM_ATTR; // add this line
static void finISR(ServoTimerSequence timerId)
{

and

static boolean isTimerActive(ServoTimerSequence timerId) ICACHE_RAM_ATTR; // and add this line
static boolean isTimerActive(ServoTimerSequence timerId)
{

it should work.

Harrison Mclean
@h4rm0n1c
Mar 10 2016 01:23
Ah, ok, I see, I was more interested in the technical reasoning, which I intended to divine from the fix, I guess it’s a matter of not triggering flash retrieval whilst executing my timer interrupt.
Michael Miller
@Makuna
Mar 10 2016 01:24
yup
something that was not a problem in the last sdk release.
Harrison Mclean
@h4rm0n1c
Mar 10 2016 01:26
sigh So I might just have to wait for espressif?
At least I know my code isn’t entirely bunk… Oh well.
Michael Miller
@Makuna
Mar 10 2016 01:43
The issue could be that the flash retrieval of the code is not reentrant, the main body of code is doing that and then this interrupt triggers; asking for code to retrieved. It could function if the correct instructions are inserted at the top of the ISR to wait for any other pending caching operations; but that is an assumption that is the only problem. Further, I have seen cache misses take as long as 8us, that's pretty big wait for an ISR.
Ivan Grokhotkov
@igrr
Mar 10 2016 02:25
@me-no-dev axTLS is more like synchronous, but it can be non-blocking if the underlying socket is non-blocking. So you can write an asynchronous wrapper for it I suppose.
@h4rm0n1c how about marking analogRead with ICACHE_RAM_ATTR? that might solve the issue
Angus Gratton
@projectgus
Mar 10 2016 02:27
Makuna: I'm not sure about that. If the flash cache is enabled, then the CPU will block automatically/transparently until the data is fetched from flash
Makuna: if the flash cache is disabled, then it will fault no matter what - and the code running outside the ISR would need to finish whatever it was doing (that required flash to be disabled) and then re-enable the cache
I guess you could temporarily enable it for the duration of the ISR and disable it when you return, but you can probably assume that if the flash cache is off then other code is doing something with the SPI flash that you shouldn't interrupt
Ivan Grokhotkov
@igrr
Mar 10 2016 02:29
Plus, if your application allows missing an interrupt or two, you can bail out of ISR if cache is disabled
Angus Gratton
@projectgus
Mar 10 2016 02:29
that's a good solution
Ivan Grokhotkov
@igrr
Mar 10 2016 02:31
I thought DMD2 is an LED display library, why does it need an analogRead within timer ISR? Just curious.
Oh, light sensor, right.
In that case you can surely bail out of ISR and assume previous reading is still good.
Angus Gratton
@projectgus
Mar 10 2016 02:36
Makuna: are you using the same timer to scan the LEDs to the display as well as update the display?
because you only need to update the display a fraction as frequently as scanning the LEDs
Ivan Grokhotkov
@igrr
Mar 10 2016 02:37
I suppose an easy way to check if cache is disabled is to compare *((int*)0x40200000) with zero
Or maybe check cache bits in DPORT
Angus Gratton
@projectgus
Mar 10 2016 02:40
does the cache mapped region of IRAM always return zero if the cache is unmapped?
Michael Miller
@Makuna
Mar 10 2016 03:01
@projectgus are you asking about my NeoPixel Library? It doesn't use ISRs; and due to its sensitive nature to the pulse shapes, I can't use the bitbang method (which uses the Cycles() feature of the chip and doesn't rely on timers). The working Methods are DMA and UART, both hardware solutions.
Angus Gratton
@projectgus
Mar 10 2016 03:02
(I wrote the original Arduino DMD2 library for Freetronics, but h4rm0n1c is the one who ported it to ESP8266)
neat that you can use the UART to create NeoPixel waveforms, I'm going to take a look at that :)
oh I see, I highlighted the wrong person. Sorry!
Michael Miller
@Makuna
Mar 10 2016 03:06
p.s. If the chip waits until code has been cached, why is there an asm instruction to wait for "instructions"?
Angus Gratton
@projectgus
Mar 10 2016 03:06
Makuna: do you have a link?
Michael Miller
@Makuna
Mar 10 2016 03:08
its in the cpu docs from xtensa; ISYNC I believe; but its been six months since I dug through that stuff.
Angus Gratton
@projectgus
Mar 10 2016 03:09
oh, right
I believe that's for on-CPU caches which we don't have. gcc for lx106 doesn't generate ISYNC instructions
Michael Miller
@Makuna
Mar 10 2016 03:10
@igrr I am away from an esp8266 for about week, so I can't confirm the fix for the servo.
Angus Gratton
@projectgus
Mar 10 2016 03:10
if it did, then to work every function call or other jump that might land on cached address space would need an ISYNC anyhow
Michael Miller
@Makuna
Mar 10 2016 03:10
Ah right, we are talking about external cache.
Angus Gratton
@projectgus
Mar 10 2016 03:11
the flash cache, where SPI flash is mapped to address space
it's not an xtensa thing - it's something espressif have bolted in there
Michael Miller
@Makuna
Mar 10 2016 03:11
I think they used common paste glue and not bolts.
(time for some sleep, getting punchy)
Angus Gratton
@projectgus
Mar 10 2016 03:12
Makuna: :)
Harrison Mclean
@h4rm0n1c
Mar 10 2016 03:26
I’m sorry, it’s analogWrite
PWM for brightness control
Harrison Mclean
@h4rm0n1c
Mar 10 2016 03:38
What’s surprising is how little I had to change to get it working, apart from that change to digitalWrite to bring it in line with behavior on the AVR I asked for last year, it has been working very well.
It does allocate a frame buffer of sorts as I understand it, drawing routines just update that and then the ISR grabs the data and spits it out over SPI along with some digitalWrite control signals and analogWrite for the brightness control. There is a fair bit going on for an ISR I guess.
Harrison Mclean
@h4rm0n1c
Mar 10 2016 03:46
I could be the way it’s structured, the ISR actually loops through all the BaseDMD instances and calls the update function in each one, that might be a little too much looping and nesting…
Angus Gratton
@projectgus
Mar 10 2016 03:47
h4rm0n1c: you can try igrr's suggestion
in the ESP8266 ISR in DMD2_Timer.cpp
put something like
if (((int)0x40200000) == 0) return;
to skip scanning if flash isn't mapped
Harrison Mclean
@h4rm0n1c
Mar 10 2016 03:47
I’m gonna try that, sorry, sometimes I’m a little slow and catching up on the chat history. Thanks.
Angus Gratton
@projectgus
Mar 10 2016 03:48
np
Harrison Mclean
@h4rm0n1c
Mar 10 2016 03:57

Ah, nah, sorry. Runs for a solid 8 seconds every time, then crash.

Ah, I’m not even getting a stack trace any more, it’s just cause: 1 crash.

Angus Gratton
@projectgus
Mar 10 2016 04:00
hmm, there must be a way to tell if spi cache is mapped. I don't have time to dig around, but take a look at what is known about the DPORT registers
h4rm0n1c: the scan_running_dmds function also needs to be marked IRAM_CACHE_ATTR
or whatever function you check for the flash mapping in - I'd suggest making a function inside the ESP8266-only part that just calls scan_running_dmds
something like
if(((int)0x40200000)) scan_running_dmds();
timer0_write(ESP.getCycleCount() + ESP8266_TIMER0_TICKS);
}
so that way you always re-queue the timer, but only call scan_running_dmds if the flash is mapped
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:05
Will do.
Is it ok if I post the stack trace I got? I managed to get it to spit one out.
Angus Gratton
@projectgus
Mar 10 2016 04:07
I don't think it will be much use, at least to me
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:07
Ah.
Hey, that means I can clear my dirty preprocessor macros out of scan_running_dmds lol.
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:16
Shit, we use digitalRead too, that might be it!
Ah, no, it does have ICACHE_RAM_ATTR.
Angus Gratton
@projectgus
Mar 10 2016 04:16
scan_running_dmds did?
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:19
I mean I decoded the stack trace and looked, forgot that we use digitalread to check the CS pin.
But its already been marked for ram caching
Angus Gratton
@projectgus
Mar 10 2016 04:20
what is the function it's crashing on?
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:22
0x4020359c: DMDFrame::~DMDFrame() at C:\Users\harri\Documents\Arduino\libraries\DMD2/DMDFrame.cpp line 221
0x401069c8: digitalRead at ?? line ?
0x40106b14: realloc at ?? line ?
0x401069c8: digitalRead at ?? line ?
0x401069e4: digitalRead at ?? line ?
0x40106a92: pwm_timer_isr at C:\Users\harri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\cores\esp8266/core_esp8266_wiring_pwm.c line 108
0x40227780: espconn_connect at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.3.0_15_08_08/esp_iot_sdk_v1.3.0/app/lwip/app/espconn.c line 320
0x40106b14: realloc at ?? line ?
0x401001e9: __mulsf3 at d:\ivan\projects\arduinoesp\toolchain\dl\gcc-xtensa\build-2\xtensa-lx106-elf\libgcc/../../../libgcc/config/xtensa/ieee754-sf.S line 722
0x40100e76: tcp_new_port at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.3.0_15_08_08/esp_iot_sdk_v1.3.0/app/lwip/core/tcp.c line 642
0x40106bb0: snprintf at C:\Users\harri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\cores\esp8266/libc_replacements.c line 212
0x40228641: espconn_kill_oldest_pcb at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.3.0_15_08_08/esp_iot_sdk_v1.3.0/app/lwip/app/espconn_tcp.c line 131
0x40228ad6: espconn_tcp_sent at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.3.0_15_08_08/esp_iot_sdk_v1.3.0/app/lwip/app/espconn_tcp.c line 475
0x40214024: fpm_do_wakeup at ?? line ?
0x40228b83: espconn_recv_hold at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.3.0_15_08_08/esp_iot_sdk_v1.3.0/app/lwip/app/espconn_tcp.c line 561
0x4020131f: timer0_attachInterrupt at C:\Users\harri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\cores\esp8266/core_esp8266_timer.c line 96
Ahhhh
I had to RDP to another machine, since I’m using Platform IO and that doesn’t have a decoder.
*another machine with Arduino IDE
Just a second...
Angus Gratton
@projectgus
Mar 10 2016 04:26
if it's actually in the destructor ~DMDFrame, that seems wrong
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:26
It’s either DMDFrame::drawBox or DMDFrame::drawFilledBox,
line 221 it said.
Angus Gratton
@projectgus
Mar 10 2016 04:26
those functions shouldn't be being called at all in interrupt context
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:26
That’s weird...
Angus Gratton
@projectgus
Mar 10 2016 04:26
maybe they're the functions where the interrupt was triggered, though
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:29
oh, bugger, I’m using 2.0.0 on the machine where I’m decoding, updating and will rebuild, test and hopefully get a trace that decodes to something that makes more sense.
Angus Gratton
@projectgus
Mar 10 2016 04:29
ah
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:29
Still new to the ins and outs of some of this, I’m used to frigging old C tools that they tought me at uni… (VC 6.0 ugh..)
Angus Gratton
@projectgus
Mar 10 2016 04:30
no problem, embedded development is frustrating :)
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:38
Yeah, it is, but god does it feel good when you’ve made a cool thing.
0x4020359c: BaseDMD::BaseDMD(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char) at C:\Users\harri\Documents\Arduino\libraries\DMD2/DMD2.cpp line 180
with 2.1.0 it decodes to that...
Harrison Mclean
@h4rm0n1c
Mar 10 2016 04:49
Oh god, I had a delay in my main loop, 100ms, removed that and suddenly it’s not crapping itself.
it was probably in system context when the ISR fired… would that make it crash?
as in yielding.
I guess this means I’m going to be using async networking too...
facepalm
As in, my test sketch had a delay in the main loop.
Harrison Mclean
@h4rm0n1c
Mar 10 2016 05:00
I set up a repo for this actually, so I’ll push this monstrosity to github and people can laugh at me.
I’ve got a simple test of wifi, NTP and the DMD that will just take hard coded credentials and display the full time and date on the display.
Tell you what, the suggestions everyone’s given are definitely going into the next PR I open on your repo, @projectgus
Harrison Mclean
@h4rm0n1c
Mar 10 2016 05:15
Nice to finally get to talk to you about DMD2, now I’ve got no excuse to finish this, up next, tying in the RTC, light sensor a web interface and the factory reset button.
If I can get proportional scaling of ambient light to display brightness and then invert that, you could use this as a kitchen clock which doubles as a night vision preserving illuminator for midnight snack runs.
Angus Gratton
@projectgus
Mar 10 2016 05:35
h4rm0n1c: glad you got somewhere. sounds like a cool project to be finishing off :)
and lol @ night vision preserving illuminator
just don't accidentally turn it to full power, you'll blind yourself
Harrison Mclean
@h4rm0n1c
Mar 10 2016 05:36
Yeah, it’s great, that’ll light up the whole kitchen, personally, I don’t know what my friends who’ve seen this are bitching about, some crying about burned corneas…
Angus Gratton
@projectgus
Mar 10 2016 05:43
:)
Lars Englund
@larsenglund
Mar 10 2016 08:57
Hmm, anyone here using the PubSubClient library?

I can't get it to connect. I can connect just fine from a PC. I create my objects like this:

WiFiClient wclient;
PubSubClient mqttClient(wclient);

then set the server ip and port like this mqttClient.set_server(mqttIp, mqttPort); then in loop i do this:

  if (!mqttClient.connected()) {
Serial.println("Not connected..");
if (mqttClient.connect("test")) {
mqttClient.set_callback(mqttCallback);
mqttClient.subscribe("inTopic");
mqttClient.publish("outTopic", "Hello!");
}
}

if (mqttClient.connected()) {
mqttClient.loop();
}

But it just prints Not connected.. once every 15s which I guess is the timeout... Am I overlooking somthing?

Ivan Grokhotkov
@igrr
Mar 10 2016 09:05
Lars Englund
@larsenglund
Mar 10 2016 09:05
Ivan Grokhotkov
@igrr
Mar 10 2016 09:05
doesn't matter much now since MDNS is a static object, but once we start unit testing libraries on the host, it will leak memory.
Lars Englund
@larsenglund
Mar 10 2016 09:07
Indeed
Harrison Mclean
@h4rm0n1c
Mar 10 2016 11:54

Thanks for all your patience and helpful suggestions you made today, everyone, you know who you are :)

I’ve got a demo clock sketch going with dynamic display brightness going, ended up using ticker for the drawing routines, the main loop is actually empty lol.

Ivan Grokhotkov
@igrr
Mar 10 2016 13:43
oh wow
esp8266/Arduino#1695
We actually had this bug for more than a year
@me-no-dev check this out
We call tcp_nagle_disable on a server tcp_pcb
and it expands into ((pcb)->flags |= TF_NODELAY)
flags is a member of tcp_pcb structure
now check out what tcp_listen function does (the one we call to start listening)
it allocates tcp_pcb_listen structure (which is smaller than tcp_pcb), fills all the fields and returns it as tcp_pcb
now tcp_pcb_listen structure doesn't have flags member!
Ivan Grokhotkov
@igrr
Mar 10 2016 13:49
so when we do tcp_nagle_disable, we write out of bounds of this structure
tzapu
@tzapu
Mar 10 2016 14:47
shouldn t strftime work?
time() and ctime() work
but strftime gives cpp.o:(.text.setup+0x68): undefined reference tostrftime’
ah, if it s using this https://github.com/esp8266/Arduino/blob/4b8fb2093fa9dcabe19e4d836c9fb5fc7becf250/cores/esp8266/time.c and not the other ones i found somewhere in the sdk, then … no, it shouldn t work :(
Michael Guntsche
@maru-sama
Mar 10 2016 15:28
@larsenglund Is your wificlient actually connected to the AP and has an IP address?
Me No Dev
@me-no-dev
Mar 10 2016 15:36
@igrr that is true if we do it on the server pcb right? client pcb is actually fine
Ivan Grokhotkov
@igrr
Mar 10 2016 15:36
Yes, this issue is only with server pcb's.
Client pcb's are fine.
unfortunately we call it on WiFiServer in the Telnet example
Victor Tseng
@Palatis
Mar 10 2016 15:37
this is cool...
Me No Dev
@me-no-dev
Mar 10 2016 15:39
I guess we can make it save the flag and add it to any client that goes through that server?
Victor Tseng
@Palatis
Mar 10 2016 15:39
strftime... maybe you have to guard the #includes with extern "C"?
tzapu
@tzapu
Mar 10 2016 15:45
well, i already got another time h included
the esp arduino core one
so… i sorted it with a nice old schoole sprintf
:P
Ivan Grokhotkov
@igrr
Mar 10 2016 15:49
@me-no-dev yes, that's a good idea
Victor Tseng
@Palatis
Mar 10 2016 15:50
@igrr @me-no-dev doing rtti with c... good idea...
tzapu
@tzapu
Mar 10 2016 17:21
NOW this is a SURPRISE. SPIFFS upload also works OTA :D
sooooo simple now :D
Lars Englund
@larsenglund
Mar 10 2016 17:54
@maru-sama turns out I had the wrong mosquitto version, shame on me..
Me No Dev
@me-no-dev
Mar 10 2016 19:50
@tzapu keep in mind SPIFFS OTA upload works only on default port and no password ArduinoOTA setups
tzapu
@tzapu
Mar 10 2016 19:54
@me-no-dev indeed, but no worries for now at least anyway
in my case
tzapu
@tzapu
Mar 10 2016 20:00
HMMM, just as a potential early warning, i ve updated to the latest github, and i am getting hardware watchdog resets...
went back to about @Links2004 ’s fix for umm_info and it all works again...
Ivan Grokhotkov
@igrr
Mar 10 2016 20:04
@tzapu do they happen at start or when the device is already running?
tzapu
@tzapu
Mar 10 2016 20:05
when device is already runnin for a bit
shortly after connecting to wifi and getting an ip
Ivan Grokhotkov
@igrr
Mar 10 2016 20:06
that's odd then, i thought that fix only applied to the very early start up
did you revert just that change or all the changes after it as well?
tzapu
@tzapu
Mar 10 2016 20:09
sorry, i may have been unclear
all the way up to that fix, fix included
works fine
something after that
makes my sketch go into hardware watchdog mode
can t pinpoint now where exactly in the commit history it starts happening
but will try tomorrow
and report back if i find something
links umm info fix is fine, it actually helped me bring my module back from a very ugly corruption of some kind
just used that as an arbitrary reset to comit point
to see if it will start working again
Ivan Grokhotkov
@igrr
Mar 10 2016 20:23
Oh, okay, so it's something after that fix. Merged a lot of stuff today.
What kind of sketch are you running?
I will test as well...
Ivan Grokhotkov
@igrr
Mar 10 2016 20:29
We have an mDNS update, a SPIFFS update, a change to attachInterrupt, and updated interrupt mask for flash operations
tzapu
@tzapu
Mar 10 2016 20:32
yes, spiffs
uses a lot of stuff
#include <FS.h>

#include <ESP8266WiFi.h>

#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>        //https://github.com/tzapu/WiFiManager

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#include <time.h>

#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include <memorysaver.h>`
sorry, got to go now, i ll play more in the morning
and try yo isolate whateve is causing it
thinking about it more, it might have been happening on spiffs.begin()
gtg, g'night
Ivan Grokhotkov
@igrr
Mar 10 2016 21:35
In that case, please try reverting this change: esp8266/Arduino@6c37fee
i forgot my guinea pig ESP in the office, so will only be able to test this tomorrow as well
sticilface
@sticilface
Mar 10 2016 23:03
think its is this esp8266/Arduino@6c37fee
i get continuous reboots with it, sketch fine without
Martin Ayotte
@martinayotte
Mar 10 2016 23:10
Yes, it seems that bit patterns are not equivalent. Also, bit3 doesn't have any define in ets_sys.h.