Getting data from a sensor in a file

Hello all,

I would like to get data (temperature for example) in a file , which another programm can read and use.

With the programm Blue iris it is possible to use data pulled from( I believe) a text file and overlay this on a camera view.
[url=http://www.cam-it.org/index.php?topic=1965.0]Loading...

Is it possible to get data from a temperature sensor and save it to a file on a computer?
Most important would be temperature readout from a fibaro universal sensor. But I have also some eversping temperature and humidity sensors.

What are the possibilities?

Thanks,
Cor

(someone allready used Blue iris macro’s to display data from a device on a camera view?)

The following Lua in a scene should append each new reading to the file /var/temperatures.txt. You could schedule the scene by interval or trigger it by some appropriate means. is the ID of your temperature sensor. You would need some mechanism to clear the file whenever you have collected the data.

local devID = <deviceID> local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID) local file = io.open("/var/temperatures.txt", "a+") file:write(temperature .. "\n") file:close()

You could also make the file name /www/temperatures.txt and then you could inspect it from a browser using: /temperatures.txt

@ RecBeckett; I think that is very close to what I need. Is it also possible not to append the data , but simply overwrite the data (2 digits) everytime.

Many Thanks,
Cor

If you change the file mode in the io.open(…) statement from “a+” to “w” then the file will contain only the last reading.

WOW!!! , Works great,I changed the code like you said:

local devID = 122 local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID) local file = io.open("/www/temperatures.txt", "w") file:write(temperature .. "\n") file:close()

and when I click it it makes the temperature.txt file, which I can check via a browser …GREAT!! :slight_smile:

Some more questions;

-When I made the scene it gave me in the middle top part in blue in the GUI an “error in LUUP file” but it is working fine… something to worry about?

  • The plan is to have in totall 5 of those scenes running 24/7 every 10 minutes or so , will this affect the performance of vera3 and the activation of other scenes and devices ( This should be a low priority scene, If it is not refreshed I will be quite happy when it does in the next round).

I will conitnue to post the progress , maybe helpfull for other people who want to use this feature of Vera in Blue iris.

Cor

-When I made the scene it gave me in the middle top part in blue in the GUI an "error in LUUP file" but it is working fine...... something to worry about?
You should not get any errors when you save the scene. I pasted the Lua from your post into a new scene and I do not get any errors. It also works. Check you don't have any stray characters, spaces or blank lines in your Luup window.
- The plan is to have in totall 5 of those scenes running 24/7 every 10 minutes or so , will this affect the performance of vera3 and the activation of other scenes and devices ( This should be a low priority scene, If it is not refreshed I will be quite happy when it does in the next round).
This code will have very little impact on Vera performance.

Are you going to be logging to five separate files? I suppose you must otherwise you will step on your previous reading. Why do you need five different scenes? You could do it all in one scene.

@RexBeckett: I am getting very close. ;D So much fun !

Attached allready a screenshot, it is the data on the left , the number “19”

Some more questions ;D

It seems that blue iris macro-option can only read from a local HD and not read the file from the network. Can the file be written to a computer on the LAN? The computer which runs blue iris has Ip adress 10.0.0.20 and the file should be saved on C:\Blueiris\macro\temperature.txt

In the attachement you see it nicely ads the digits from the file ( as a test I copied the temperatures.txt to the computer which runs blue iris.) Is it possible to add text via the LUUP code as well?, Ideally it would be nice if the digits would be fetched and next to it “degrees C” would be written. like this (In blue iris I can only add text in front of the variable:

20 degrees C.

Your suggestion to use just 1 scene , that would make it much easier , That would mean to copy paste this LUUP code 5 times in a row with the different Device ID and txt file? But I guess I cannot simply copy paste this code 5 times in a row :-\ What would be the correct code?

Again , many many thanks,
Cor

It seems that blue iris macro-option can only read from a local HD and not read the file from the network. Can the file be written to a computer on the LAN?
That is not so easy. It depends on what facilities your other system has. You may be better finding a way to get your remote machine to pull the file from Vera's web server.
Is it possible to add text via the LUUP code as well?, Ideally it would be nice if the digits would be fetched and next to it "degrees C" would be written.
That bit is easy: [code]file:write(temperature .. " degrees C\n")[/code]
But I guess I cannot simply copy paste this code 5 times in a row
If you are reading different temperature variables and writing to different files then you would, basically, paste the code five times and edit the device ID and file name.

If you wanted to visualise the data recorded directly in vera, you could also write to a variable container. The VC app allows you to capture 5 variables which seems to also meet the requirements.

@ RexBeckett, The machine which runs Blue iris is an Intel I5 on the same LAN (computer is 10.0.0.20 , vera3 is 10.0.0.10). I can install a programm there to pull the file from vera … But how? , are there programms for that,or can that be done with a (simple) batch file? For the moment I was only able to copy the txt-file to the computer via winscp.

Tonight when I am back behind the computer I will try the “degrees C” … many thanks.

@ Brientim: thanks for the suggestion , doing it via the LUUP code is almost complete, I think I will continue using this … but that VC APP,I cannot not find that in the app list , it is a vera plugin?

Cor

You can find the app here:
http://apps.mios.com/plugin.php?id=1458

The forum is here:
http://forum.micasaverde.com/index.php?topic=9022.0

Using this you will still need to use luup to write to the variable container.

Cor,
If you are using winscp, check out this on scripting it:

And here is an example of how to automate it:

http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/

I think WinSCP is going to be your easiest route as @SOlivas suggests. You already have a connection profile established so a simple script to change local and remote directories and get the remote file should take care of it.

BTW: You could make your display string more compact by replacing degrees with the symbol:

file:write(temperature .. " \176C\n")

Slowly I am getting there.

@Brientim: cool plugin , I will not use it for this project , but I can use it for something else … thanks for the tip.
@ SOlivas & RexBeckett … pffff it’s difficult;

I am trying that script [url=http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/]http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/[/url] , But I need to change it a bit;
This is the script from that website:

1 option batch continue 2 option confirm off 3 open lab-net-01 4 lcd C:\FTP 5 synchronize both -delete 6 synchronize both C:\FTP / 7 exit

As I understand it, it syncs both ways…not good ,I need to sync it from remote to local.

I changed here and there some bits,
These are some options of the scipts: [url=http://winscp.net/eng/docs/scriptcommand_synchronize#syntax]synchronize command :: WinSCP

option batch continue option confirm off open vera3 lcd C:\blueiris\macro\files synchronize local -delete synchronize local C:\blueiris\macro\files /www\blueiris exit

It is working , but I am not sure if it is correct,can someone take a look at it (line 5 and 6)?
I want the files from vera to the local directory C:\blueiris\macro\files ( what does the line “synchronize local -delete” do? )

The other issue I have ,is the directory in vera. I created the directory blueiris in vera www\blueiris
( see attachment) , but when I run the LUUP code , the oatemp.txt is not created;
Luup code:

local devID = 122 local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID) local file = io.open("/www/blueiris/oatemp.txt", "w") file:write(temperature .. " \176C\n") file:close()

Is there something wrong with the directory I created? or something else?
When I remove , it works and the txt file is created in the www directory, but I need it in a seperate directory since the script wants to copy otherwise all files.

Many thanks again ,
Cor

To get a single file from Vera, try this:

option batch continue option confirm off open vera3 lcd C:\blueiris\macro\files cd /www get oatemp.txt exit

How did you create your directory in /www? I just tried it out and it works just fine. I created the directory by clicking F7 - Create Directory and then changed the pathname in the Lua accordingly. Using a folder would allow you to synchronize multiple files with a single command but it wouldn’t be any quicker than putting multiple get commands in the script. Personally, I would use individual get lines in the WinSCP script.

Edit: A new thought: Did you refresh WinSCP’s display after running the Vera scene? A new file will not show-up in the list unless you click on the refresh icon or hit ctrl-R.

You don’t need to delete the Vera files with the WinSCP script as they are overwritten whenever the Vera script runs. There is probably more overhead in deleting and recreating a file than in just rewriting its only record.

Done !! :slight_smile:

It’s working Perfectly, attached a screenshot of one of the camera’s in my heating room.

When I logged in This morning , I saw the file was created , so I think it was due to the very slow internet connection I had to the computer running Blue iris ( I am 2000 miles away from home for the moment and use a programm to logon to the computer , black and white screen and very slow).

I didn’t use your “get” command , but copied all files ( 3 for the moment) to a local directory, it is working fine, is there a benefit to use the “get” command if I use the Blueiris folder only for these files I want to copy?
This is what I am using for the moment:

option batch continue option confirm off open vera3 lcd C:\blueiris\macro\files synchronize local C:\blueiris\macro\files /www/blueiris exit

Many thanks for your help guys! , much appreciated :slight_smile:


For people who are interested , here is the how to:

Create a scene , with a schedule which repeats itself every ?? minutes/hours.
LUUP code for 1 device (where 122 is the device ID and /www/blueiris/oatemp.txt is the file in a folder blueiris created with winscp)

local devID = 122 local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID) local file = io.open("/www/blueiris/oatemp.txt", "w") file:write(temperature .. "\176C\n") file:close()

The code to create more txt files from the devices.

[code]local devID = 122
local temperature = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,devID)
local file = io.open(“/www/blueiris/oatemp.txt”, “w”)
file:write(temperature … “\176C\n”)
file:close()

local devID = 43
local temperature = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,devID)
local file = io.open(“/www/blueiris/bathroomtemp.txt”, “w”)
file:write(temperature … “\176C\n”)
file:close()

local devID = 48
local temperature = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,devID)
local file = io.open(“/www/blueiris/heizungtemp.txt”, “w”)
file:write(temperature … “\176C\n”)
file:close()[/code]

create with winscp a directory www/blueiris in your vera.

On the computer which runs Blue iris follow this procedure:
[url=http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/]http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/[/url]

The script ( where I copy the files from vera www/blue iris to my computer to :C:\blueiris\macro\files

option batch continue option confirm off open vera3 lcd C:\blueiris\macro\files synchronize local C:\blueiris\macro\files /www/blueiris exit

Open in blue iris the setup
Open Options>Macro Tab
Click on %1 Type in line
Click on Set to file…
This will open a Windows Explorer window that you will navigate to the network location
that the text file is located such as:.
C:\blueiris\macro\files\oatemp.txt
Click on this text file.

Open the camera properties >> video>> edit text and graphic overlay.
On the top field “enter some text %1”
click OK

That’s it ( in a nutshell)

Cor

I’m happy to hear it is all working. It looks good on the still. 8)

I didn't use your "get" command , but copied all files ( 3 for the moment) to a local directory, it is working fine, is there a benefit to use the "get" command if I use the Blueiris folder only for these files I want to copy?
There would be no benefit in using [b]get[/b] if you always want to synchronize all the files in the folder.

The line lcd C:\blueiris\macro\files in your WinSCP script is now redundant as you are specifying the local directory in the synchronize… command. It isn’t hurting anything, though.

ohhh :-\ This threads needs a follow up.

I just updated to the latest version and there is a small change in there which make this text overlay not work as good.
It is just a very small thing I noticed , but I don’t know how to change it ( if it is possible).

With this code:

local devID = 122 local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID) local file = io.open("/www/blueiris/oatemp.txt", "w") file:write(temperature .. "\176C\n") file:close()

The file is saved with the cursor on the next line, basically instead of a 1 line txt, there are now 2 lines/rows , where 1 is empty. Blue iris still reads this second line and for the background ( to read the text better), the background is now 2 rows, which is not so good.

Is there a way that the txt files is saved with the cursor on the first line and no “enter” on the second line?

thanks,
Cor

Try changing:

file:write(temperature .. "\176C\n")

to:

file:write(temperature .. "\176C")

The string \n is a new-line character.

@RexBeckett: thanks , that did the trick :slight_smile:

Cor