Need script to automatically upload data from serial port

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Dave_G
Posts: 453
Joined: Thu 21 Jul 2011, 13:53

Need script to automatically upload data from serial port

#1 Post by Dave_G »

Hi all,

Just joined the forum and also new to Linux so decided to try Puppy as my entry point for my Linux "adventures".

Can anyone shed some light on how one would go about writing a script that would automatically upload some data to a website (preferably via http but ftp also OK) each time a byte is received on the serial port?

Thanks in advance,
Dave.

User avatar
darkcity
Posts: 2534
Joined: Sun 23 May 2010, 19:16
Location: near here
Contact:

#2 Post by darkcity »

Welcome to Puppy,

More details would be handy. Do you intend writing the program in BASH script?

User avatar
Dave_G
Posts: 453
Joined: Thu 21 Jul 2011, 13:53

Help needed by newbie

#3 Post by Dave_G »

Hi darkcity,

A Bash script would be fine.
What I require is the script to check the serial ports buffer (for received ASCII data) and then automatically upload that as a text file to a server.
The file will always have the same name and any previous uploads are over-written by the new upload.

Thanks,
Dave.

User avatar
darkcity
Posts: 2534
Joined: Sun 23 May 2010, 19:16
Location: near here
Contact:

#4 Post by darkcity »

My suggestion would be re-post in the Programming section (which isn't really off topic)

http://www.murga-linux.com/puppy/index.php?f=46

If you have no joy there. Post here again in this thread and I will look into it.

User avatar
Dave_G
Posts: 453
Joined: Thu 21 Jul 2011, 13:53

Help needed by newbie

#5 Post by Dave_G »

No problem, thanks.
Apologies for posting in the wrong place.

Dave.

Master_wrong
Posts: 452
Joined: Thu 20 Mar 2008, 01:48

#6 Post by Master_wrong »

Hi,

I will try to help...

in your problem, you need to scan serial port which will trigger upload or download right ???

i check some program and find these

http://stackoverflow.com/questions/3701 ... bstitution
# initialize serial port
stty 2000000 -ixon icanon </dev/ttyUSB0

# check settings
stty -a -F /dev/ttyUSB0

# in one terminal - read from serial port
while (true) do cat -A /dev/ttyUSB0 ; done

# in other terminal - write to serial port
echo "1234567890" > /dev/ttyUSB0

# back to first terminal, I now have:
# $ while (true) do cat -A /dev/ttyUSB0 ; done
# 1234567890$
# ...
about sending files i find these...
http://crunchbanglinux.org/forums/topic ... tp-server/
cd $filedir
wput ftp://$user:$pass@$host/$targetfile

other alternative....
http://nixcraft.com/shell-scripting/157 ... ouble.html
I got it to work!!!!!
The problem was when this line : "cat /dev/ttyS0 > $mytestfile"
would get called, the script would run correctly but it would keep the serial port open forever like bill stated above, which is why i could never run a single command after wards.

So to fix this I did this:

#!/bin/bash
stty -F /dev/ttyS0 9600 cs7 parenb parodd -cstopb clocal -crtscts -ixon -ixoff
mytestfile=mmof.txt
cat /dev/ttyS0 >> $mytestfile

I have this script run in the background at boot up, and it continues to run the entire time the computer is on leaving the port open.

Then I just run the other script:

#!/bin/bash
stty -F /dev/ttyS0 9600 cs7 parenb parodd -cstopb clocal -crtscts -ixon -ixoff
echo "200 201" > /dev/ttyS0

i hope that help
Cluster-Pup v.2-Puppy Beowulf Cluster
[url]http://www.murga-linux.com/puppy/viewtopic.php?p=499199#499199[/url]

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

Re: Need script to automatically download data

#7 Post by Moose On The Loose »

Dave_G wrote:Hi all,

Just joined the forum and also new to Linux so decided to try Puppy as my entry point for my Linux "adventures".

Can anyone shed some light on how one would go about writing a script that would automatically upload some data to a website (preferably via http but ftp also OK) each time a byte is received on the serial port?

Thanks in advance,
Dave.
bash can do actions on the network directly. A HTTP transfer of a text file is not all that hard to do. You send the HTTP post line over the network and then a blank line and then the body of the file.

User avatar
Dave_G
Posts: 453
Joined: Thu 21 Jul 2011, 13:53

#8 Post by Dave_G »

Thank you Master_wrong and Moose On The Loose, very handy info.
It will take a newbie like me a bit of time to understand it all but like
they say, you don't learn 'till you try.

I will give it a bash (oooh dreadful pun).

Dave.

Post Reply