Run blynk-ser.sh on reboot

How to run blynk-ser.sh on reboot. I am connecting local server on pi running latest jessie version. To execute the script i have to download socat using> sudo apt-get install socat and change TO_TYPE=“SSL” to TO_TYPE=“TCP” . Now i am able to execute script using " bash /home/pi/blynk/scripts/blynk-ser.sh ". Its working fine
I add @reboot bash /home/pi/blynk/scripts/blynk-ser.sh to crontab but its not executing on restart.
I executed sudo chmod +x /home/pi/blynk/scripts/blynk-ser.sh to make it executable

Now i added @reboot /home/pi/blynk/scripts/blynk-ser.sh to crontab but its still not executing on restart.

Kindly guide how to run script on startup
Thanks

@reboot sh /home/pi/blynk/scripts/blynk-ser.sh &

and

@reboot sudo sh /home/pi/blynk/scripts/blynk-ser.sh &

sudo sh /home/pi/scripts/blynk-ser.sh
/home/pi/scripts/blynk-ser.sh: 3: /home/pi/scripts/blynk-ser.sh: pushd: not found
/home/pi/scripts/blynk-ser.sh: 5: /home/pi/scripts/blynk-ser.sh: popd: not found
/home/pi/scripts/blynk-ser.sh: 47: /home/pi/scripts/blynk-ser.sh: function: not found
/home/pi/scripts/blynk-ser.sh: 50: /home/pi/scripts/blynk-ser.sh: Syntax error: “}” unexpected

and without sudo?

$ /home/pi/scripts/blynk-ser.sh
Resetting device /dev/ttyACM0…
Warning: Server connection may be insecure!
[ Press Ctrl+C to exit ]
Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> TCP:127.0.0.1:8442,nodelay
2017/09/20 20:07:47 socat[1247] N opening character device “/dev/ttyACM0” for reading and writing
2017/09/20 20:07:47 socat[1247] N opening connection to AF=2 127.0.0.1:8442
2017/09/20 20:07:47 socat[1247] N successfully connected from local address AF=2 127.0.0.1:35094
2017/09/20 20:07:47 socat[1247] N starting data transfer loop with FDs [5,5] and [6,6]
2017/09/20 20:07:47 socat[1247] E read(5, 0x1b369c0, 8192): Resource temporarily unavailable
2017/09/20 20:07:47 socat[1247] N exit(1)
Reconnecting in 3s…
Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> TCP:127.0.0.1:8442,nodelay
2017/09/20 20:07:50 socat[1250] N opening character device “/dev/ttyACM0” for reading and writing
2017/09/20 20:07:50 socat[1250] N opening connection to AF=2 127.0.0.1:8442
2017/09/20 20:07:50 socat[1250] N successfully connected from local address AF=2 127.0.0.1:35096
2017/09/20 20:07:50 socat[1250] N starting data transfer loop with FDs [5,5] and [6,6]

Now its working but only when i manually run @raspberrypi:~ $ /home/pi/scripts/blynk-ser.sh

never with crontab

It might be a path issue for all the relevant files.
Create a script file called autoblynk.sh in your /home/pi directory and paste these details into it:

#!/bin/sh
cd /home/pi/scripts
echo "Starting serial connection .........."
bash blynk-ser.sh

then chmod +x autoblynk.sh

try without crontab first, so

sh autoblynk.sh

And if it runs OK try crontab

@reboot sh autoblynk.sh &

Edited autoblynk.sh to use bash because blynk-ser.sh is set up for bash.

pi@raspberrypi:~ $ sh autoblynk.sh
Starting serial connection …
blynk-ser.sh: 3: blynk-ser.sh: pushd: not found
blynk-ser.sh: 5: blynk-ser.sh: popd: not found
blynk-ser.sh: 47: blynk-ser.sh: function: not found
blynk-ser.sh: 50: blynk-ser.sh: Syntax error: “}” unexpected

correction :
its working with

#!/bin/sh
cd /home/pi/scripts
echo “Starting serial connection …”
bash blynk-ser.sh

now trying crontab

What do the following commands give you?

uname -a

cat /proc/device-tree/model

cat /proc/cpuinfo

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l GNU/Li nux
pi@raspberrypi:~ $ cat /proc/device-tree/model
Raspberry Pi 2 Model B Rev 1.1pi@raspberrypi:~ $ cat /proc/cpuinfo
processor : 0
model name : ARMv7 Processor rev 5 (v7l)
BogoMIPS : 57.60
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5

processor : 1
model name : ARMv7 Processor rev 5 (v7l)
BogoMIPS : 57.60
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5

processor : 2
model name : ARMv7 Processor rev 5 (v7l)
BogoMIPS : 57.60
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5

processor : 3
model name : ARMv7 Processor rev 5 (v7l)
BogoMIPS : 57.60
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5

Hardware : BCM2835
Revision : a01041
Serial : 000000003b3f7191
pi@raspberrypi:~ $

its working in crontab if i set it to run every minute or at particular time but its not working with @reboot

@ngoyat pretty sure it’s working OK here, this is an extract from ps aux

root       376  0.0  0.6   6172  2948 ?        S    19:36   0:00 sudo sh autoblynk.sh
root       418  0.0  0.2   1900  1208 ?        S    19:36   0:00 sh autoblynk.sh
root       423  0.0  0.6   6172  2984 ?        S    19:36   0:00 sudo bash blynk-ser.sh
root       452  0.0  0.5   4636  2632 ?        S    19:36   0:00 bash blynk-ser.sh
root       494 88.6  0.7   4856  3500 ?        R    19:36   7:59 socat -d -d FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 openssl-connect:blynk-cloud.com:8441,cafile=/home/pi/scripts/certs/server.crt,nodelay

I just need to upload a sketch to the Leonardo to be 100% sure it’s running OK.

Maybe your connection is dropping but it does actually start with crontab and @reboot

I am using sudo because socat might need it:

@reboot sudo sh autoblynk.sh &

One thing i noticed if after rebooting pi, I unplug and replug arduino it connects

Are you using a Leonardo, if not which Arduino is it and do you have TTL available?

i am using arduino uno.
I have ttl FTDI and arduino pro mini. Will try with it tomorrow

i tried using arduino nano and its working fine. May be there is something wrong with arduino uno.
Thanks for the help

@ngoyat because I’m such a massive fan, not, of Arduino’s for iOT projects (eh @Gunner) I tested the crontab with my Arduino’s and it wasn’t very satisfactory.

Below is a “foolproof” system but I would recommend backing up your SD card before you try.

  1. Remove the script call from crontab and place it in /etc.rc.local before the last exit line as:

sudo sh autoblynk.sh (don’t bother with the & suffix)

  1. You need to ensure you have SSH access to the Rpi because with the entry in /etc/rc.local the bootup script will never get to the login prompt. It will be running the socat stuff over and over again, which is probably what most people want for Blynk purposes.

  2. Tested OK with Nano’s, Leonardo’s and Nano’s modified with Uno bootloader (because of an old WDT bug) and will check the Mega as soon as it becomes free. If you need to get to the login prompt on the Rpi issue the following command via SSH and then kill the process with sudo kill xxx

ps aux | grep rc.local (to find the xxx process number to kill)

  1. Killing the process will not stop the socat script looping as required, it simply allows the bootup script to get to the login prompt (if required).

Confirming it’s fine for a Mega too.

Wouldn’t recommend hooking up Arduino’s to the early model A Rpi’s as they were seriously lacking power on the USB port.

Tested on a model B and all seems ok, so B onwards should be fine.

I might test a Zero or Zero W as it’s probably a better way of adding internet to an Arduino than the ESP shield method. Slightly more expensive but probably much easier to accomplish.

I can confirm the RpiZeroW is also fine to provide internet access to Blynk’s cloud server for your ageing Arduinos.

Note: for all the Rpi’s it depends whether you are running Wheezie, Jessie or Stretch as to which shell commands you require. I’ll probably not be using Stretch any time soon but Jessie requires bash and the first line of /etc/rc.local needs to be:

#!/bin/bash

and the line before exit 0 should be:

sudo bash /home/pi/autoblynk.sh not sudo sh /home/pi/autoblynk.sh

You might ask why you would us a $10 Rpi as your internet gateway when you could use a $2 ESP-01?

  1. ESP-01’s are not user friendly.
  2. ESP shield connections can be a nightmare to set up.
  3. The Rpi is a “computer” with all the benefits that provides, unlike the ESP which is just a MCU.
  4. For the $10 you can have a Blynk Rpi local server, Blynk Rpi client and a reliable internet gateway for your Arduino all on a slimline PCB.

Don’t get me wrong I’m not saying you should be using Arduino’s at all as the EziBlynk method is with plug and play ESP’s but if you really, really must use an Arduino then shacking up with the Rpi might be a good move for you.

HTH

Just as I finish the last post I get an email from Seeed for the new plug and play PCB for ESP-01’s.

This project adds useful components around ESP-1 cheap ESP8266 modules, such as program and reset button, 5V to 3.3V converter, UART connector, power and GPIO pins, and micro-usb power in.

10 boards for just $4.90 (+ presumbaly p&p) but they are just boards. I happen to have a stock of those exact same micro USB boards so I might look into this.

https://www.seeedstudio.com/espboard-v2-g-1022544

Veering well off topic now but whatever. Contacted the board designer for a bill of materials (BOM) and the GitHub is at https://github.com/MicroJoe/espboard with the closest thing to a BOM at https://github.com/MicroJoe/espboard/blob/master/kicad/espboard.sch