diff --git a/raspberry-script.sh b/raspberry-script.sh new file mode 100644 index 0000000..77eb2ae --- /dev/null +++ b/raspberry-script.sh @@ -0,0 +1,16 @@ +#!/bin/bash +#Starting local nc server at background +(nc -l -p 9000 &) && echo "Server is running and accepting incoming connections at localhost:port 9000!" +#nodeserial.js will be executed to the background as to write serial data to a file that will be then sended to local nc +node nodeserial.js >> json_data.txt 2>/dev/null & +#if something fails inside nodeserial.js, e.g. with the parsing of JSON data, an attempt is made to restart nodeserial.js script. +while [ $? -ne 0 ] +do + sleep 1; + node nodeserial.js >> json.data.txt 2>/dev/null & +done +echo -e "Data from IMU sensor are now being send over to the server:\n\n" +#JSON data are now read continuously from file json_data.txt and are send with piped netcat to our local netcat instance +tail -f json_data.txt | nc 127.0.0.1 9000 +#Job 1 now is brought to the foreground at standard output, i.e the local nc server with the json data received +fg 1