How to get a new line in output file raspberry Pi

Moderator: leecollings

Post Reply
Jan-
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

Post by Jan- »

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. :twisted:
SweetPants

Re: How to get a new line in output file raspberry Pi

Post by SweetPants »

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
Jan-
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

Post by Jan- »

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.
SweetPants

Re: How to get a new line in output file raspberry Pi

Post by SweetPants »

Jan- wrote:But using it on the rasp-B (Lunix) all the output is printed on one line.
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 minute
Jan-
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

Post by Jan- »

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()
SweetPants

Re: How to get a new line in output file raspberry Pi

Post by SweetPants »

Good to hear it's working.
maxmizer
Posts: 8
Joined: Sunday 25 October 2015 8:17
Target OS: Windows
Domoticz version:
Contact:

Re: How to get a new line in output file raspberry Pi

Post by maxmizer »

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)
jannl
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

Post by jannl »

What exactly is in line 15 and which variables are used.
It looks like one of them has no value.
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: How to get a new line in output file raspberry Pi

Post by jvdz »

That means that this statement failed:

Code: Select all

file = io.open("/ram/logfiletemp.txt", "a")
Did you check the path for the file you try to open?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
maxmizer
Posts: 8
Joined: Sunday 25 October 2015 8:17
Target OS: Windows
Domoticz version:
Contact:

Re: How to get a new line in output file raspberry Pi

Post by maxmizer »

Thank you, It was wrong syntax
I open another thread on my work viewtopic.php?f=23&t=8928
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest