NodeMCU Custom Firmware Problems - esp8266

After flashing an ESP8266 with a custom NodeMCU build ist doesn't work as with the version before. For the custom build I've used the cloud service at http://nodemcu-build.com, the prior version was nodemcu_float_0.9.6-dev_20150704.bin from github.
The problem now is that communication over serial port now is quirky, sometimes it seems to work, sometime not.
Example:
When I list files:
> for k,v in pairs(file.list()) do l = string.format("%-15s",k)
print(l.." >..v.." bytes") end
stdin:1: ')' expected near 'bytes'
>
>
Or when I execute node.chipid()
þ®ÈJÀHƒÌHÜÞ{½ÝÕ½{ommw¯­íë= node.chipid()
> = node.cèipid()
stdin:1: '<eof>' expected near 'è'
> = node.,+¥‘¡)
stdin:1: '<name>' expected near ','
> = node.,+¥‘¡)
stdin:1: '<name>' expected near ','
> = node.chipid()
13840686
> = node.chipid()
13840686
> = node.chipid()
13840686
>
In the above exapmle I've executed node.chipid() six or seven times, the latter two times it worked. Errors of this kind happen over and over again, uploading lua files doesn't work, although success was stated.
I've tried it with LuaLoader and LuaUploader, it is reproducable. When flashing the older firmware, everything works as expected, but it doesn't provided some modules I want to use. For flashing I've used ESP8266Flasher.exe.
What is going wrong? What did I do wrong? Changing baud rates did make some differences, but the problems persist.

I think the default baud changed with the latest version, try setting the reading side's baud rate to 115200.
Alternatively, try setting the baud rate of the ESP lower (9600) using lua code in the init file, mayby 115200 is too fast for your serial chip.

If you're using ESPlorer to send Lua code/files try turning on 'turbo' mode in the settings. I vaguely remember issues like that.

Related

Lua ESP8266 script expecting extra =

I am trying to test a proximity sensor with my ESP8266, however the test code I am using keeps failing.
Whenever I run the code, I get an error: motion sensor.lua:1: '=' expected near 'int'
I should also mention I am using ESPlorer v0.2.0
const int PIRSensorOutPin = 2; //PIR Sensor OUT Pin
void setup() {
Serial.begin(9600);
pinMode(PIRSensorOutPin, INPUT);
}
void loop()
{
if (digitalRead(PIRSensorOutPin) == LOW)
{
Serial.println("Person detected!"); //Print to serial monitor
}
else {;}
}
What am I doing wrong?
The Lua interpreter doesn't understand C++.
You're running NodeMCU firmware which runs Lua files. But you're trying to run Arduino C++ code. That's not going to work. To run this code you would have to add ESP8266 support to your Arduino IDE, compile your code and flash it onto the ESP.
Alternatively write your code in Lua.
https://github.com/esp8266/Arduino
https://www.nodemcu.com/index_en.html
What am I doing wrong?
Using the wrong programming language.
NodeMCU wants to run Lua code and you're giving it C code instead, which just can't work.
How do I fix it? (implied)
You can use the arduino IDE to write C++ code for ESP8266, but since you already seem to have everything set up to run Lua code, I suggest just using that instead.
The C code you provided could be rewritten into Lua using the NodeMCU api like this:
local pin = 2 -- The number of the I/O Pin
local type = "down" -- Trigger on falling edge
-- https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpiotrig
gpio.trig(pin, type, function()
print("Movement detected, proceding to exterminate!")
end)

ESP32 NodeMCU uart input matching strings problem

I created a small project on ESP32 with nodemcu firmware which communicates with a sim808 module via uart2. My problem is, that the response from uart many times is not easy for interpretation within lua and nodemcu.
Here a short example of my code:
uart.on(2, "data", "\r", function(data)
print("Checking UART: "..data)
if (string.match(data, "RING")) then
print("Someone rings")
elseif (string.match(data, "CLIP:")) then
print("Phone number: "..data) -- shortened, I know that the whole line will appear
elseif (string.match(data, 'NO CARRIER')) then
print("Ring canceled")
else
print("Dont understand")
end
end, 0)
In above case - RING and NO CARRIER inputs are matching correctly and the proper info is given.
I have also many other such searchings which works. But when I look for the phone no (+CLIP:...) the code is ignorig this input, however I see it on the serial console output:
Checking UART:
Dont understand
Checking UART:
+CLIP: "+xxxxxxxxxxx",145,"",0,"",0
Checking UART:
Dont understand
I see also that this specific answer has new line character after and the loop goes again with no chars, maybe that's why the code can't find it, but the build in function uart.on should check every line (\r).
The same issue when I get some bluetooth command, also can't put it to a variable.

ZeroBrane remote debugging embedded script

I work on image processing application in Embarcadero C++ Builder XE10.2 that executes Lua scripts. I use LuaJIT with FFI to share image data. Everything works fine. I've downloaded ZeroBrane studio and tried to see if I can debug scripts executed from "host" C++ application, so I've included
package.path = package.path .. ";C:/Portable_App/ZeroBraneStudio/lualibs/mobdebug/?.lua"
package.cpath = package.cpath .. ";C:/Portable_App/ZeroBraneStudio/bin/clibs/?.dll"
require("mobdebug").start()
before any function in the script is called. However, when the script is loaded and executed (on C++ side):
FResult = lua_pcall(FLs, 0, 0, 0);
host program crashes with "floating point division by zero" exception. It crashes on
require("mobdebug").start()
Without this line script works OK. Any clue?
It's not possible to tell what may be going wrong based on the provided information, but you can try to get the stack trace (using this SO answers), which should provide more information about what's leading to the error.
The only division that I'm aware of is in the serialization code that uses tostring(1/0) code to generate platform-independent NaN values. Would this lead to "floating point division by zero" error in your Lua configuration?
(Update to include the solution mentioned in comments) The issue was related to BCC compiler settings on how to handle FPU exceptions. One way is to manipulate FP control: _clear87(); _control87(MCW_EM, MCW_EM); or to set arithmetic exception mask: SetExceptionMask(exAllArithmeticExceptions);.

BizHawk 2.1.1: read("*number") always returns 0 in Lua

I'm trying to run the brilliant Mar I/O artificial intelligence written in Lua (more on this at https://youtu.be/qv6UVOQ0F44)
The AI runs successfully in the Lua (v.5.1) console of the BizHawk emulator (v.2.1.1), but I'm getting an error when trying to reload a previous state of the algorithm.
After opening the file, it seems like file:read("*number") will always return 0, whereas read("*all") and "*line" both read the content correctly. I've also tried "*n" with no luck.
Full script at: https://pastebin.com/ZZmSNaHX
function loadFile(filename)
local file = io.open(filename, "r")
pool = newPool()
pool.generation = file:read("*number")
pool.maxFitness = file:read("*number")
...
function writeFile(filename)
local file = io.open(filename, "w")
file:write(pool.generation .. "\n")
file:write(pool.maxFitness .. "\n")
...
The file generated starts with:
18[LF]
1938[LF]
...
But still, I only see 0s in the console:
console.writeline("Gen " .. pool.generation) --> "Gen 0"
console.writeline("Max Fitness " .. pool.maxFitness) --> "Max Fitness 0"
What's also puzzling is that this script has been discussed in different forums and no one seems to report the same issue.
I found out that the BizHawk emulator is using a customized version of Lua.
This issue appeared in version 2.1.1 of the emulator. Previous releases are working fine.
Thanks for your help community
The format to read a number is 'n', file:read('n'). See https://www.lua.org/manual/5.3/manual.html#pdf-file:read for details on read() format specifiers.
Around that time, BizHawk added an alternate c# lua implementation 'kopilua' in an effort to workaround deep crashy problems. One of kopilua's several shortcomings is noncompliant string parsing and file IO. You must use config > customize > advanced > Lua+LuaInterface in order to use normal lua; it won't have this problem.

tmr.create() fails in dirt simple code

On an ESP8266, a LUA tmr.create() fails. Just a single line of code from the nodemcu docs. I've yet to get this working; stumped; have found nothing on the 'net here or forums. Posted in several other places with no replies. Odd
Basic node commands work. And, here's the thing that's getting me: some timer functions work - for instance tmr.alarm() does - but tmr.create() doesn't.
QUESTION 1: if the tmr module is loaded, isn't the entire module loaded, not just parts of it?
When I try this one line copied directly from the NodeMCU docs, it fails:
local mytimer = tmr.create()
with the usual message, I understand to mean an object is undefined:
stdin:1: attempt to call field 'create' (a nil value)
QUESTION 2: What am I missing or doing wrong?
Nodemcu's flasher successfully sent its default
INTERNAL://NODEMCU # 0x00000
NodeMCU 0.9.5 build 20150318
The board is an Adafruit Huzzah ESP8266, not a NodeMCU board. They both use the same ESP12, I think, so that shouldn't matter (or I hope it doesn't :-/)
NodeMCU 0.9.5 build 20150318
There's your culprit. That version is ancient. create() was added much later. Build a recent version from the master branch, https://nodemcu.readthedocs.io/en/master/en/build/ (note master in the URL), and flash that one.

Resources