Skip to main content

You are here

Connection to Linux-shell

6 posts / 0 new
Last post
AndreasZoeller
Connection to Linux-shell

I am using a JeeNode with an extended RFM12Demo-sketch as an I/O-board an OpenWRT-system (a special kind of Linux) on a BR6104KP-Router. The communication goes via the serial interface of the JeeNode to a serial interface on the router.

I am using the following shellscipt to get the data from the JEENode and process them :

stty 19200 -raw -crtscts -echo -ixoff -F /dev/ttyS1

while true ; do read help < /dev/ttyS1 echo 0 > /sys/class/gpio/gpio12/value echo $help

here comes some processing ...

echo 1 > /sys/class/gpio/gpio12/value done

I have a DS18B20-sensor connected and i use digital inputs and outputs.

Everything worked fine beside that randomly a message from a digital input was missed. This input is connected to a reedrelais on a gascounter. Everytime i get a pulse i send a message via the serial port and increase a variable which is also included in the message. So you can see that sometimes a message is missing. You can also see that the time between 2 messages is 2 times as normal. Now i have connected more DS18B20-sensors. Every 20 seconds the JeeNode is reading this sensors and sending for each sensor a message via serial. But i get only the message from the first sensor. When i use a terminalprogram to read this messages i get all messages. This messages comes very short one after the other. I think the problem is that the reading of the ttyS1 is not buffered.

Does anybody have an idea how to solve this ?

I would like to stay with the shellscript, because this router has only 16MB Ram, this means it is difficult to install an additional scriptlanguage like perl on python.

A. Zoeller

RogerClark

Andreas,

This doesn't really answer your question, but it is possible to cross-compile C to make a binary that runs on a OpenWRT box - however I think you need to be running Linux on your development machine.

Alternatively... I'm not sure what processing you are doing on the OpenWRT box, but if you are purely using it as a gateway to the Internet, you may be better off just buying a $5 ethernet board from eBay etc and using JCW's Ethercard library to send you data to the Internet or run a basic web server.

Cheers

Roger Clark, Melbourne Australia

AndreasZoeller

Hello Roger,

the point is that this OpenWRT-Router offers a full Linux-system with connecttion to the internet via a GSM-modem, a lot of storage on a USB-stick, a realtimeclock which is updatet by ntp-server .... This system is at a remote location and i want to check the heating-system there. I am running a http- and a ssh-server on it. I can connect via a reverse-ss-tunnel. I can change the shellscripts online and even reprogram the connected JeeNode. So the system is quite comfortable. I think to have this on microprocessorsystem like JeeNode needs quite a lot of programming.

It would be very fine to find a solution how to buffer the reading of the ttyS1-interface with the Linux-shell.

A. Zoeller

padvinder95

Could you try putting a sleep 1 (or sleep 60) in your processing block and see if you miss a lot more messages? If yes, then it indeed seems to have to do with buffering of ttyS1.

What do you use GPIO12 for?

A solution could be to direct all the incoming serial data to a textile (cat </dev/ttyS1 >seriallog &) and then process that logfile in your script. Since the two run in parallel, slow processing will only mean a build-up of data in the seriallog-file.

AndreasZoeller

I will test to add the sleep-command.

The GPIO12 is connected to a led and is just for visualisation that there are coming data.

I will also test the recommendation to buffer it with an additional logfile. But for understanding : The background process (cat </dev/ttyS1 >seriallog &) is writing data from ttyS1 in the file seriallog. But i need to read seriallog at the same time. Is this possible ? Will the file not getting bigger and bigger ? Isn't this a task for (named) pipes ? I haven't used this until now. I have to investigate.

Thank you for your ideas and lets see.

A. Zoeller

padvinder95

I actually never tried reading a file that is continually being written to by another process such as cat/serial, but I do know I've been able to follow logfiles in "real-time" using tail -f or tailf, but of course the question is when cat actually writes to the file or closes the connection: after every byte/line written or after termination of the process. In the first case you're fine, in the second case I would make a separate program to read the serial port and write on a per-line basis (line basis? grammar) to a file (while read help <dev/tty do cat help >> seriallog done) and read that file in another script.

Premium Drupal Themes by Adaptivethemes