These are chat archives for esp8266/Arduino

5th
Sep 2015
Neil Kolban
@nkolban
Sep 05 2015 15:04 UTC
I have a project (porting JavaScript runtime to ESP8266) where I need to be able to "block" to make a TCP/IP connect call ... what this means is that the JavaScript runtime wishes to call a functionc called "connect" and not return until the TCP connection has been established. In ESP land, this is a challenge because of its asynchronous architecture. However, I believe the Arduino libraries have solved this problem by somehow yielding control back to the ESP8266 in the middle of logic and then somehow returning back to where we are. I am wondering if anyone can assist with reproducing this technique for the JavaScript ESP8266 support?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:06 UTC
@nkolban how much stack does javascript runtime need?
Neil Kolban
@nkolban
Sep 05 2015 16:08 UTC
Howdy .... I don't know yet. What I am doing is porting the Espruino project onto the ESP8266. It is running just fine. Comments on the Espruino forum suggest that it is about 10-12K for stack.
However ... it assumes blocking network calls.
And so what I need to do is make espconn_xxx calls and then block waiting for their callbacks.
Ive been looking at your cont.S code .... but don't yet know if that could even be a possibility for the Espruino project.
I was also trying this path ... http://bbs.espressif.com/viewtopic.php?f=7&t=1055
Ivan Grokhotkov
@igrr
Sep 05 2015 16:10 UTC
i see... that's a lot.
i thought javascript developers were quite at home with asynchronous network requests? :)
Neil Kolban
@nkolban
Sep 05 2015 16:13 UTC
Oh they are ... sending and receiving are 100% asynchronous with callbacks ... but the formation of a connection is synchronous ... in the library implementation for networking. We can write our own APIs for making ESP8266 specific networking ... but are trying to embrace what has been before and leverage their architecture.
In the Espruino project ... they support a wide variety of platforms and networking devices ... and have provided a place for "device specific" functions ... and the networking device specific function assumes a blocking connect.
Ivan Grokhotkov
@igrr
Sep 05 2015 16:13 UTC
simply calling soft_wdt_feed will not achieve what you need. you need to return execution flow to the scheduler (ets_run function) so that it can dispatch tasks which deal with processing of network packets.
Neil Kolban
@nkolban
Sep 05 2015 16:13 UTC
Do you know what soft_wdt_feed actually does?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:14 UTC
if resets the flag of software watchdog timer
Neil Kolban
@nkolban
Sep 05 2015 16:14 UTC
For what purpose?
When would one want to do that?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:15 UTC
when one tries to do some lengthy activity (e.g. save a lot of data to SD card) and doesn't want the watchdog timer to reset the system.
it's a hack, obviously. but some people were requesting it, so it was made a public API.
Neil Kolban
@nkolban
Sep 05 2015 16:16 UTC
So why would one simply not stop the watchdog timer before that activity and restart it later with soft_wdt_stop() and soft_wdt_restart()?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:18 UTC
that's an option, but calling soft_wdt_stop is less safe — your program might end up in a state where it doesn't call restart(). you might argue that your program might end up in an endless loop calling wdt_feed as well, true, but as I said, it's a hack...
Neil Kolban
@nkolban
Sep 05 2015 16:18 UTC
Ok. I am assuming that you solved the yield puzzle for the Arduino libraries?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:22 UTC
That was actually why i decided to do this arduino-esp8266 project in the first place. I was interested in writing networking programs in a sequential manner, while in fact using an asynchronous networking stack. So I wrote this context switching code which would enable coroutine-like program behaviour.
Neil Kolban
@nkolban
Sep 05 2015 16:23 UTC
I think youve come up with something very important here. Is it a component/function/library/technique that could be used in other projects?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:25 UTC
This is a pretty common technique — some languages (like python) have this built-in.
Not C and C++ unfortunately.
Neil Kolban
@nkolban
Sep 05 2015 16:25 UTC
Would it be possible for me to try and re-use what you built in the Espruino project?
Ivan Grokhotkov
@igrr
Sep 05 2015 16:32 UTC
sure, you just need cont.h,.S, cont_util.c, and a few lines of code in your main()
does espruino have an eval loop?
Neil Kolban
@nkolban
Sep 05 2015 16:34 UTC
Aweesome ... I'll give it a deep study. I don't suppose by any chance that you have a write up of how to use it? I think what you have invented here is going to come up again and again and again and I doubt I will be the last person that comes along looking to achieve this task in an environment other than the Arduino libraries.
Ivan Grokhotkov
@igrr
Sep 05 2015 16:40 UTC
I have written about it on the forum on a couple of occasions. need to find that text and draw some diagrams. explaining stack switching is hard without some drawings, especially since most developers today have never used longjmp's...
Neil Kolban
@nkolban
Sep 05 2015 17:51 UTC
If it will help, I'll try and write up a recipe pointing to the Arduino code for the implementation. I'll search the forums and see if I can find the articles you mentioned.
Ivan Grokhotkov
@igrr
Sep 05 2015 18:33 UTC
ok, i found my post, turned out it was on a Russian forum :) I'll go and write some docs...
Neil Kolban
@nkolban
Sep 05 2015 18:34 UTC
Awesome ... thank you sir
Holger Lembke
@holgerlembke
Sep 05 2015 19:33 UTC
Hi all. /me still alive. Trying to get the OTA flashing to work, but found no description what is needed. Just installed python 2.7, have the latest staging version, choose OTA as flash method and uploaded serial the esp8266/Arduino#268 file...
'''
All I get is
Starting on 0.0.0.0:48266
Upload size: 305344
Sending invitation to: COM4
...
socket.gaierror: [Errno 11004] getaddrinfo failed
What else to configure?
Neil Kolban
@nkolban
Sep 05 2015 20:14 UTC
Hmmm ... it seems that the macro ETS_INTR_WITHINISR isn't present in SDK 1.3.
Ivan Grokhotkov
@igrr
Sep 05 2015 21:06 UTC
it looks like this:
inline bool ETS_INTR_WITHINISR()
{
    uint32_t ps;
    __asm__ __volatile__("rsr %0,ps":"=a" (ps));
    // PS.INTLEVEL check
    return ((ps & 0x0f) != 0);
}
it's doesn't work fully as expected, and it's meant mostly as a check that someone doesn't call yield from an ISR unexpectedly
so you can as well remove its use in your javascript port
@holgerlembke you haven't selected the ESP8266 IP address in the ports menu.
Sending invitation to: COM4
You have a regular COM port selected
Holger Lembke
@holgerlembke
Sep 05 2015 21:25 UTC
@igrr : there is no ip address....
Juppit
@Juppit
Sep 05 2015 22:36 UTC
@holgerlembke try DNS_SD_Arduino_OTA.ino in ESP8266mDNS.
If you use windows, you need apple bonjour.
Try to restart the Arduino IDE after selecting uploading with OTA.
But! You need Arduino 1.6.5, it definitly dont't works with 1.6.6