How to get a new line in output file raspberry Pi
Moderator: leecollings
-
- Posts: 17
- Joined: Saturday 08 February 2014 13:57
- Target OS: Windows
- Domoticz version:
- Contact:
How to get a new line in output file raspberry Pi
I would like to monitor some devices and write the values to a file using the rasp.
file = io.open("/home/pi/domoticz/scripts/logfiletemp.txt", "a")
file:write(datum,';',weekdag,';',tijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',buitentemp,';',windrichting,';',wind,';'
,windvlaag,'\n')
file:close()
The problem is the output is printed on one line. How can I fix that. \n is not working.
file = io.open("/home/pi/domoticz/scripts/logfiletemp.txt", "a")
file:write(datum,';',weekdag,';',tijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',buitentemp,';',windrichting,';',wind,';'
,windvlaag,'\n')
file:close()
The problem is the output is printed on one line. How can I fix that. \n is not working.
Re: How to get a new line in output file raspberry Pi
file:write("\n") maybe?
Hmm, weird. This works on the CLI version of LUA
#!/usr/bin/lua
file = io.open("/ram/logfiletemp.txt", "a")
datum = 'datum'
weekdag = 1
tijd = '10:00'
tempnieuw = 23
afgerond = 2
opwarmgraden = 2
buitentemp = 23
windrichting = 'nw'
wind = 7.5
windvlaag = 'ja'
-- This line should be one line
file:write(datum,';',weekdag,';',tijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',buitentemp,';',windrichting,';'
,wind,';',windvlaag,'\n')
file:close()
output of cat /ram/logfiletemp.txt
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
Do you run this from a Domoticz LUA script? If yes, it looks like something in the embeded LUA
Hmm, weird. This works on the CLI version of LUA
#!/usr/bin/lua
file = io.open("/ram/logfiletemp.txt", "a")
datum = 'datum'
weekdag = 1
tijd = '10:00'
tempnieuw = 23
afgerond = 2
opwarmgraden = 2
buitentemp = 23
windrichting = 'nw'
wind = 7.5
windvlaag = 'ja'
-- This line should be one line
file:write(datum,';',weekdag,';',tijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',buitentemp,';',windrichting,';'
,wind,';',windvlaag,'\n')
file:close()
output of cat /ram/logfiletemp.txt
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
datum;1;10:00;23;2;2;23;nw;7.5;ja
Do you run this from a Domoticz LUA script? If yes, it looks like something in the embeded LUA
-
- Posts: 17
- Joined: Saturday 08 February 2014 13:57
- Target OS: Windows
- Domoticz version:
- Contact:
Re: How to get a new line in output file raspberry Pi
Thanks for the quick reply.
I run this from a lUA script of Domoticz. I have tested it on my windows PC and it then it is working. But using it on the rasp-B (Lunix) all the output is printed on one line.
I run this from a lUA script of Domoticz. I have tested it on my windows PC and it then it is working. But using it on the rasp-B (Lunix) all the output is printed on one line.
Re: How to get a new line in output file raspberry Pi
If I run the above script on a Raspberry as a script_time_test.lua script on Domoticz 1.1664, i got the output line by line every minuteJan- wrote:But using it on the rasp-B (Lunix) all the output is printed on one line.
-
- Posts: 17
- Joined: Saturday 08 February 2014 13:57
- Target OS: Windows
- Domoticz version:
- Contact:
Re: How to get a new line in output file raspberry Pi
Thanks for your help and support! This one is working on my rasp.:
file:write(datum,';',weekdag,';',tijd,';',opwarmtijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',gevoelstemperatuur,';',windrichting,';',wind,';',windvlaag)
file:write("\n")
file:close()
file:write(datum,';',weekdag,';',tijd,';',opwarmtijd,';',tempnieuw,';',afgerond,';',opwarmgraden,';',gevoelstemperatuur,';',windrichting,';',wind,';',windvlaag)
file:write("\n")
file:close()
Re: How to get a new line in output file raspberry Pi
Hello I tried this script but returns
Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_test.lua:15: attempt to index global 'file' (a nil value)
Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_test.lua:15: attempt to index global 'file' (a nil value)
-
- Posts: 625
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: How to get a new line in output file raspberry Pi
What exactly is in line 15 and which variables are used.
It looks like one of them has no value.
It looks like one of them has no value.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: How to get a new line in output file raspberry Pi
That means that this statement failed:
Did you check the path for the file you try to open?
Jos
Code: Select all
file = io.open("/ram/logfiletemp.txt", "a")
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: How to get a new line in output file raspberry Pi
Thank you, It was wrong syntax
I open another thread on my work viewtopic.php?f=23&t=8928
I open another thread on my work viewtopic.php?f=23&t=8928
Who is online
Users browsing this forum: No registered users and 1 guest