lua uart.alt(1) how to make it work - lua

I was hoping to use the alt uart on esp8266 and tried the following:
uart.alt(1)
uart.setup(0, 19200, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
unfortunately, it give me an error "attempt to call field 'alt' (a nil value)". Why? I thought that I was setting uart to alt(1) in this case. Not sure why it's nil value. Any comments?

"attempt to call field 'alt' (a nil value)"
This error indicates that uart is a table, but that the field alt is nil. Since you cannot call nil like a function you get this error. The error has nothing to do with the argument you are providing.
uart.alt should be available by default in a NodeMCU environment, as indicated by both the documentation and implementation.
Have you done anything earlier in your program, or firmware compilation, that would result in the alt field becoming nil?

It may be UART module is missing somehow though it's ON by default in https://nodemcu-build.com/
When you connect to your board from ESPlorer at startup, you should see some initial info about the firmware and it's modules.
Like:
NodeMCU custom build by frightanic.com
branch: master
commit: b96e31477ca1e207aa1c0cdc334539b1f7d3a7f0
SSL: true
modules: adc,bit,bme280,cjson,crypto,encoder,file,gpio,http,i2c,mdns,mqtt,net,node,pwm,sntp,spi,tmr,uart,websocket,wifi,ws2812,tls
Do you see UART in your startup console?

Related

PowerDNS - DNSQuestion is always nil

I have setup a PowerDNS (4.0.4-1+deb9u4) upon Debian 9 with a MySQL backend successfully and the system was resolving hosts correctly. I am attempting to add scripting to the recursor and have used the examples, Lua script examples. I have pointed the pdns-resolver's conf correctly at my lua script, and I see my log statements print correctly, but I am consistently receiving an error regarding the DNSQuestion instance being empty for all of the example lua functions.
For example:
function preresolve(dq)
pdnslog("Got question for "..dq.qname:toString().." from "..dq.remoteaddr:toString().." to "..dq.localaddr:toString())
return true;
end
Results in :
STL error (a.root-servers.net/A from 127.0.0.1): Trying to cast a lua variable from "nil" to "b" (meaning the DNSQuestion instance is null).
Clearly the lua script is running, but for some reason, all the dq instances are empty.
Is there anything that I may have misunderstood or am missing that would cause the parameter to be nil?
Have your function return true or false so it will not return nil by default.

Error trying to configure esx_addonaccount

I am trying to make a fivem server and have been able to configure esx_addonaccount once before, but now that I have needed to restart my project it is not seeming to work. My database is considered fine, and I am running a completely vanilla install minus the esx framework plugins and esx_addonaccount, which is the problem. This occurs when I load into the server anytime.
Error running system event handling function for resource esx_addonaccount: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: #esx_addonaccount/server/main.lua:87: attempt to index a nil value (local 'xPlayer')
stack traceback:
#esx_addonaccount/server/main.lua:87: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:219: in function <citizen:/scripting/lua/scheduler.lua:218>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:218: in function <citizen:/scripting/lua/scheduler.lua:182>
Please help!!
#esx_addonaccount/server/main.lua:87: attempt to index a nil value (local 'xPlayer')
Above is a line from your error. It basically says that in resource esx_addonaccount, in folder ./server/, in file main.lua, in line 87 you are trying to access xPlayer variable, but in this specific case it equals nil. This means that either you have not initialized ESX correctly or somehow xPlayer is not existing - eg. player with given ID doesn't exist.
The best bet would be to check the whole 'path' of this variable - where is it created, initialized and populated with data.
ESX resources should work out of the box, so if it doesn't, then try to follow the installation instructions in their README files or on github and see if you did everything to correctly install them on your server.

Why is wifi.sta nil even after wifi.setmode(wifi.STATIONAP)?

EDIT: what I'm trying to do is essentially configure the station after
the softap is running a TCP server.
I get a panic error for wifi.sta being nil when I call wifi.sta.config(station_cfg) even after I configured it properly before.
When I do:
function connectHib()
wifi.setmode(wifi.STATIONAP)
[AP config here]
station_cfg={}
station_cfg.ssid = ""
station_cfg.pwd = ""
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg)
end
It works fine, but when I call it, then start a server with srv=net.createServer(net.TCP) and then call the following function:
function validateSTA()
station_cfg={}
station_cfg.ssid = _G.wifi
station_cfg.pwd = _G.senha
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg) -- this creates an error
wifi.sta.connect()
end
It gives me a PANIC error on the commented line. I'm just trying to reconfigure the STATION module only and then tell it to connect so I can validate the conection.
I'm using:
NodeMCU custom build by frightanic.com
branch: master
commit: 67027c0d05f7e8d1b97104e05a3715f6ebc8d07f
SSL: false
modules: adc,file,gpio,net,node,pwm,sjson,tmr,uart,wifi
build created on 2018-04-16 13:55
powered by Lua 5.1.4 on SDK 2.2.1(cfd48f3)
What bugs me is why it seems like it has not been "declared" before, but it works on the first function... I thought wifi. was global like _G. variables.
It also works if I call the functions separately on the ESPlorer command line on an ESP without my init.lua.
I also tried the debug firmware and the only odd thing I saw poping up was wifi_event_monitor_handle_event_cb that is called every 4 secconds or so.
Thanks guys, any help is apreciated as I'm stuck about a week now.
Like many other script languages, lua doesn't have declarations, only assignments.
You should perform checks what is wifi's value during the first and the second calls. It seems that at first you are using it as a table, and in the second function you try to use it as a string in the station_cfg.ssid = _G.wifi.
Or the reason is that global variables are not "like _G", they're stored in _G.

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.

DHT and NodeMCU completely not working?

I directly copy-pasted the dht.md example from the official NodeMCU GitHub into my Script window like so:
But upon saving to ESP8266 I get an error:
init.lua:3: attempt to index global 'dht' (a nil value)
Which NodeMcu firmware (version) do you use?
Make sure you get (build) the latest (1.5.1), easiest to get it from here:
http://nodemcu-build.com/
And -make sure- you click the little box saying 'DHT' there.

Resources