-->
Page 1 of 2

New LUA firmware and old codes do not match

PostPosted: Mon Mar 29, 2021 11:03 am
by Pittiplatsch
Hello forum,

I am a LUA newbie (to put it nicely ... and I don't really want to become a specialist)) and would like to work through these instructions:

https://www.instructables.com/Motorized-WiFi-IKEA-Roller-Blind/

I flashed firmware from January 2021 on the ESP-32 and it somehow no longer fits with the instructions or the new LUA commands / old firmware ...

NodeMCU 3.0.0.0 built on nodemcu-build.com provided by frightanic.com
branch: release
commit: 136e09739b835d6dcdf04034141d70ab755468c6
release: 3.0.0-release_20210201
release DTS: 202102010145
SSL: true
build type: float
LFS: 0x0 bytes total capacity
modules: file,gpio,mqtt,net,node,pwm,tmr,uart,wifi,tls
build 2021-03-02 20:04 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)

The wifi_setup.lua of the instructions says:

Code: Select all-- file: setup.lua
local module = {}

local function wifi_wait_ip() 
  if wifi.sta.getip() == nil then
    print("IP unavailable, Waiting...")
  else
    tmr.stop(1)
    gpio.write(pin_led,1) --off
    print("\n====================================")
    print("ESP8266 mode is: " .. wifi.getmode())
    print("MAC address is: " .. wifi.ap.getmac())
    print("IP is "..wifi.sta.getip())
    print("====================================")
    mq.start()
  end
end

local function wifi_start(list_aps) 
    if list_aps then
        gpio.write(pin_led,0) --on
        for key,value in pairs(list_aps) do
            if config.SSID and config.SSID[key] then
                wifi.setmode(wifi.STATION);
                wifi.sta.config{ssid=key,pwd=config.SSID[key]}
                wifi.sta.connect()
                print("Connecting to " .. key .. " ...")
                -- config.SSID = nil  -- can save memory
                tmr.alarm(1, 2500, 1, wifi_wait_ip)
            end
        end
    else
        print("Error getting AP list")
    end
end

function module.start() 
  print("Configuring Wifi ...")
  wifi.setmode(wifi.STATION);
  wifi.sta.getap(wifi_start)
end

return module


I successfully googled that the command "wifi.sta.config (key, config.SSID [key])" has to be replaced by "wifi.sta.config {ssid = key, pwd = config.SSID [key]}".

Now comes the next error message
"wifi_setup.lua: 29: attempt to call field 'alarm' (a nil value)"
That has something to do with the "old" command "tmr.alarm".
The solution would be to find / use a firmware from 2017 or to replace the "tmr.alarm" command ... :roll:

I hope for help from you ... (and I can't reach the author / won't get in touch). ;)

Greetings

Re: New LUA firmware and old codes do not match

PostPosted: Mon Mar 29, 2021 3:26 pm
by marcelstoer
That tutorial is for ESP8266, not for ESP32 (you mentioned ESP32 somewhere). You got the correct firmware, though; the one from the release branch which is for ESP8266.

No need to google for each syntax error. Just head to the documentation for the operation in question e.g. https://nodemcu.readthedocs.io/en/lates ... istaconfig or timer alarm https://nodemcu.readthedocs.io/en/lates ... #tobjalarm.

P.S. Lua is not an acronym.

Re: New LUA firmware and old codes do not match

PostPosted: Tue Mar 30, 2021 2:13 am
by Pittiplatsch
@marcelstoer

Thanks for the answer. I've already been to these help pages. But I don't understand anything about it, nothing at all. I have no idea about programming and just want to follow the instructions.
(If I drive a car I don't have to be a developer of engines or drives ... don't get me wrong) :?

The easiest solution would be to find a firmware from 2017, right?

Re: New LUA firmware and old codes do not match

PostPosted: Tue Mar 30, 2021 1:47 pm
by marcelstoer
Pittiplatsch wrote:(If I drive a car I don't have to be a developer of engines or drives ... don't get me wrong)


Driving a car would be analogous to using those roller blinds that someone else built for you, not building them. I get your point, though.

Pittiplatsch wrote:The easiest solution would be to find a firmware from 2017, right?


You could try building a firmware from that frozen 1.5.4.1-final branch that my cloud builder offers. You might just get lucky and it is API-compatible with what those Lua scripts expect.