I´m missing my callback from the gpio.serout() function. I´m suspecting the uart is somehow blocking it, since it only disappears once some input is given. Preferrably if much input is given at once. Here some isolated code:
pin = 6;
occupied = false;
-- callback resets the occupied flag
function seroutCallback()
occupied = false;
end
-- gets run every 50ms
function timerCallback()
if occupied then
print("occupied");
else
print(" not occupied");
occupied = true;
-- gpio.serout() is asynchronus, if a callback is provided
-- the times dont matter
gpio.serout(pin, gpio.LOW,{5000,5000,5000,5000,5000,5000,5000}, 1, seroutCallback);
end
end
tmr.register(3, 50, tmr.ALARM_AUTO, timerCallback);
tmr.start(3);The output looks something like this: ( the numbers are some random input echo´d over the uart)
(run @9600 baud)
[...]
not occupied
not occupied
not occupied
not occupied
not occupied
not occupied
not occupied
not occupied
1234567890123456789012345678901234 not occupied
567890123456789012345678901234567890123456789011 not occupied
234567890123467890123456789012345678901234567890 not occupied
123456789012345678901234567890123456789012345678 not occupied
901234567890123456789012345678901234567890123456 not occupied
7890123456789012345678901234
stdin:1: unexpected symbol near '12345678901234567890123456789012345678901234567890123456789012345678901234567890112345678901234678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234'
> occupied
occupied
occupied
occupied
occupied
occupied
occupied
occupied
occupied
occupied
occupied
occupied
[...] ( it never recovers, the callback went missing)
In this isolated state you need quite a lot of data to break it. In the application I want to use it , it disappears after a couple of symbols. ( With a server running in the background). Running at 160 MHz improves slightly. Running at higer baud too, but my project requires 9600. The waveform outputted by serout() looks fine. Tried different nodemcu versions. I´m out of ideas.
Another weird thing: Before I implemented this check, (check if the callback finished) I was getting cryptic error messages somewhat like: "already freed 0x[random adress] \n Attempt to call a nil value in LUA Api" (not the exact error message, but google didnt find anything). I suspect the callback didnt get freed properly and was sitting somewhere waiting to crash my project. Digging in the source code i found that the serout_async function emits a low priorty task, but since I´m new to Micros, the source code is more cryptic to me than the error message.
So my question is: Is this a bug or is NodeMCU just not capable of running a reliable uart?
If you are interested: The project is a communication interface to my selfmade drone. Im able to fly it over wifi ( at least in my living room. I need to do some range testing on the weekend, I know it wont be good