Serout to log file simple qustion

tremmert

New Member
Hi everyone,
Im using the picaxe and Dallas DS18B20 to read temperature and output it to hyperterm. I would like to upload this data to weather underground every minute or so. I figured that the best way was to have a program log the comport activity, and output to a file. Then use another script to read the log file, and upload that data to WU. The problem that im having is the log file looks like this:

71
71
72
71
etc...

I want the log file to just contain one number, and not the previous readings. Anyone have any idea on this issue?

Thanks,
Tommy
 

moxhamj

New Member
Can an administrator kindly move this thread to the main discussion forum :)

It depends on the language, but in vb.net the code is
FileOpen(1, Myfile.txt, OpenMode.Output) ' open the text file for output
PrintLine(1, Str(mynumber)) ' save mynumber which is an integer or floating point value
FileClose(1) ' close the file

Each time you run this it will overwrite the previous myfile.txt so it will only contain one value.

If you want to go for vb.net have a read of http://www.instructables.com/id/Worldwide-microcontroller-link-for-under-20/ and http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
 

benryves

Senior Member
It depends on the language, but in vb.net the code is
FileOpen(1, Myfile.txt, OpenMode.Output) ' open the text file for output
PrintLine(1, Str(mynumber)) ' save mynumber which is an integer or floating point value
FileClose(1) ' close the file
Even easier;

Code:
File.WriteAllText("MyFile.txt", MyNumber.ToString())
:)
 

moxhamj

New Member
There you go - a solution in just one line of code. I'm impressed!

vb.net is free and is part of the .net family which includes java and C. So you can pick your language these days as all these languages are converging into one at the moment.

Where you say you have "one program to monitor the com port and another to upload", you can do this all in one program and make things even easier.
 
You didn't say how you were uploading the file to Weather Underground. If you're using FTP or HTTP, you don't even need to use a file:

Code:
dim client as new WebClient()
client.UploadString("<ftp | http>://address.of.server/", Temperature.ToString())
Sure, it takes two lines of code, but no messy temp file laying around. Depending on how your code looks, you might not even need a variable:

Code:
dim port as new SerialPort()
dim client as new WebClient()

port.PortName = "COMn" ' Set to your com port, like COM1.
port.BaudRate = 2400 ' Set to the baud rate you use.
port.ReadTimeout = 500 ' Wait for data for half a second.
port.Open()

while (true)
   client.UploadString("ftp://server.address/filename.ext", port.ReadByte().ToString())
end while
You can take a look at my PicaxeNET library if you want some ideas -- http://www.puddlehaven.com/Picaxe/PicaxeNET.zip

Chuck
 
Last edited:
Top