-1

I have Arduino connected to computer over RS-232 (only TxD, RxD and GND).

Arduino only send data to computer and computer receive it. Computer do not transmit anything to Arduino.

Computer is WiFi router with OpenWrt linux with 16MB RAM and 4MB flash for system. I do not have free enough space for "good tool" like python (I have the same working program on x86 PC written in python).

Arduino send data to PC +- each 60 seconds. Data has following format:

SENSOR1;12.34;95.47
ABC245;34.5;75.1

2 sensors each have 2 values. Line is ended using <CR><LF>. I can modify this "protocol" to for example one line like (or any other):

SENSOR1;12.34;95.47|ABC245;34.5;75.1

so on wifi router I need little program which read this string every minute and save it to variable. This variable insert to curl and send to remote server. Can I send data to server without curl (with less ram/flash usage)?

I would like to use pure bysybox sh (bash is to big).

I found Bash script: save stream from Serial Port (/dev/ttyUSB0) to file until a specific input (e.g. eof) appears :

#!/bin/bash
while read line; do
     if [ "$line" != "EOF" ]; then
          echo "$line" >> file.txt
     else
          break
     fi
done < /dev/ttyUSB0

awk `
/EOF/ {exit;} 
 {print;}` < /dev/ttyUSB0 > file.txt

is it good choice to use/modify these script? Is there any other better solution?

Community
  • 1
  • 1
martin
  • 1,707
  • 6
  • 34
  • 62
  • A lot of parts here, but I'd be surprized if Busybox supports `/dev/ttyUSB0`. Easy way to find out is open terminal, and do `ls -l /dev/ttyUSB0`. If you get an error message, you have to figure out if it correctable. Otherwise that could should work using `#!/bin/sh` for the first line. Consider using `flag` to ask moderator to move to `http://askubuntu.com` (or maybe there is http://Arduino.stackexchange.com`?) Good luck. – shellter Oct 24 '14 at 02:01
  • Busybox support `/dev/ttyUSB0`, it is normal device file like `/dev/ttyS0`. Why askubuntu/askarduino? Shell is programming language too... – martin Oct 28 '14 at 00:52
  • I see a lot of questions related to `/dev/ttyUSB*` on askubuntu. Here on S.O. `shell` questions usually get answered within minutes, so I'm referring you there just so you can get some help (I didn't down vote this question). Good luck! – shellter Oct 28 '14 at 02:48
  • As I originally said, "a lot of parts here", For starters, pose your question either as a busybox `sh` problem or as a `bash` problem. 2. Sending data on RS232, then what is ttyUSB0 about? 3. back-tics around your awk program? Those should be single-quote chars like `'`. 4. aside from the back-tics problem, I can't see the difference in functionality between the `while read line ; do ... ; done < ....` loop and the `awk ...` program. You don't really mean to run them both, do you? IHMO, your question needs a re-write, to focus on 1 environment, and 1 problem/solution. Good luck! – shellter Oct 28 '14 at 02:54
  • Yes, re-reading your question for the 5th time now, I see that I've ignored that you have 3 pieces of hardware. Maybe on your rewrite, include a simple line diagram of the communication flow. Going to bed:-) Good night and good luck. – shellter Oct 28 '14 at 02:56

1 Answers1

1

Why not give a try to ser2net pakage?
This will allow forward the serial port to the server. It work ok on OpenWrt

Lua is buid in. A script in Lua ca read also from the serial port , but you neet to set the port parameters first with stty

stty 9600 raw < /dev/ttyUSB0
lua myscript < /dev/ttyUSB0
lalo-uy
  • 46
  • 2
  • Can I work with control lines "DTR, RTS, CTS, ..." on remote PC if I use `ser2net` or `socat`? – martin Oct 24 '14 at 21:55