LUA: bad argument #1 to 'read' (invalid format)

Moderator: leecollings

Post Reply
puttemanp
Posts: 5
Joined: Thursday 15 October 2015 13:24
Target OS: NAS (Synology & others)
Domoticz version:
Location: Tremelo, Belgium
Contact:

LUA: bad argument #1 to 'read' (invalid format)

Post by puttemanp »

Good morning all,

After upgrading to V3.8153 I have the folowing error in my logfile upon calling a LUA script: bad argument #1 to 'read' (invalid format)

Code: Select all


--|1502624.00

print ('Script Water Started')
commandArray = {}

local thisfilename = "/home/pi/dev-domoticz/scripts/lua/script_device_water.lua"
local virtualcounter_idx = "53"
local switchName = "water"

if devicechanged [switchName] == 'On' then

-- Open this file and read the first line
        file = io.open (thisfilename, "rb")
        sContents = file:read ("*1")
        file:close()

-- Parse and update the countvalue
        foo,snumber = sContents:match("([^,]+)|([^,]+)")
        local countvalue = snumber + 0,50
        local newline = foo .. "|" .. string.format("%.2f", tostring (countvalue))

-- Update virtual counter device
        ts = virtualcounter_idx .. "|0|" .. string.format("%2.f",tostring(countvalue))
        commandArray['UpdateDevice'] = ts

-- Write back new counter value
        local file = io.open(thisfilename, "r+")
        file:write(newline)
        file:close()

        end

        return commandArray
This script used to run correctly before, it's only after the upgrade to the latest version (compiled from source as I had to make modifications for Nest Field Test compatibility).

Any insights as I don't seem to find this specific error on the board or using Google.

Thx

P.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA: bad argument #1 to 'read' (invalid format)

Post by jvdz »

Is "rb" correct for io.open? Can't find the b option in the manual I have.
It also has the filename thisfilename, which is the script file?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
puttemanp
Posts: 5
Joined: Thursday 15 October 2015 13:24
Target OS: NAS (Synology & others)
Domoticz version:
Location: Tremelo, Belgium
Contact:

Re: LUA: bad argument #1 to 'read' (invalid format)

Post by puttemanp »

Honestly, I'm a noob where Lua is concerned. All I know is that untill the day before yesterday, the script worked. Upgraded and the error appeared, counter is not updated anymore.

The original script can be found in another thread : https://www.domoticz.com/forum/viewtopi ... 306#p61306

I merely adapted it for my use 2 years ago.

Greetz

P.
mauip
Posts: 2
Joined: Sunday 05 November 2017 15:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA: bad argument #1 to 'read' (invalid format)

Post by mauip »

Hi there,

i kindly ask you for help-i am totaly new to lua and domoticz.

I tried to use the scripts provided on the link below:

https://www.domoticz.com/wiki/ESP8266_WiFi_module

but i get always an error on the t=ds18b20.read() in the domoticz.lua script. (domoticz.lua:7: bad argument #1 to 'read' (Must be function)

I am using a ESP8266-01 with the following Firmware:

NodeMCU custom build by frightanic.com
branch: master
commit: 443e8219527f5b2190324a969a4586f9d3d731bf
SSL: false
modules: bme280,cron,dht,ds18b20,encoder,enduser_setup,file,gpio,http,net,node,ow,rtcfifo,rtctime,sjson,spi,tmr,uart,websocket,wifi
build built on: 2017-11-02 22:02
powered by Lua 5.1.4 on SDK 2.1.0(116b762)


Many thanks for your Support.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest