Page 1 of 1

How to get a new line in output file raspberry Pi

Posted: Wednesday 02 April 2014 11:15
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:

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

Posted: Wednesday 02 April 2014 12:53
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

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

Posted: Wednesday 02 April 2014 13:38
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.

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

Posted: Wednesday 02 April 2014 14:36
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

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

Posted: Wednesday 02 April 2014 21:34
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()

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

Posted: Wednesday 02 April 2014 21:48
by SweetPants
Good to hear it's working.

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

Posted: Sunday 15 November 2015 13:28
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)

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

Posted: Sunday 15 November 2015 13:32
by jannl
What exactly is in line 15 and which variables are used.
It looks like one of them has no value.

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

Posted: Sunday 15 November 2015 13:38
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

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

Posted: Sunday 15 November 2015 18:03
by maxmizer
Thank you, It was wrong syntax
I open another thread on my work viewtopic.php?f=23&t=8928