Start cayenne-ser.sh on boot

  1. Disable IPv6.

     sudo nano /boot/cmdline.txt
    

    At the end of the line add ipv6.disable=1

  2. Enable networkd and networkd-wait-online services.

     sudo systemctl enable systemd-networkd.service
     sudo systemctl enable systemd-networkd-wait-online.service
    
  3. Create the udev rule.

     sudo nano /etc/udev/rules.d/95-cayenne_connection.rules
    

    Add the line

     KERNEL=="ttyACM0", ENV{SYSTEMD_WANTS}="cayenne_connection.service"
    

    Change KERNEL=="ttyACM0" to your serial port if needed.

  4. Create the service file

     sudo nano /etc/systemd/system/cayenne_connection.service
    

    Add the following

     [Unit]
     Description=Connect to Cayenne
     Requires=network-online.target
     After=network.target network-online.target
    
     [Service]
     ExecStart=/home/pi/cayenne/Cayenne-MQTT-Arduino/extras/scripts/cayenne-ser.sh -c /dev/
    

    Change ExecStart=/home/pi/cayenne/Cayenne-MQTT-Arduino/extras/scripts/cayenne-ser.sh to the path of your script

2 Likes

Thanks for sharing this @adam.

Thanks for all the work you did on this @adam

Hello again @adam . We worked on this solution about a year ago and things have been going fairly well. I’ve recently been debugging an issue with @shramik_salgaonkar to adapt this application for a new project. Simply put, all seems to go well following the steps listed except for the fact that the arduino Mega making the connection to the Pi4 via the cayenne-ser.sh script needs to have the USB unplugged and reconnected before the arduino makes its connection to cayenne. Thoughts on this?

if the arduino is connected and detected by pi, then you can start the script with detected port.

In the past, if the arduino is connected to port when the Pi boots, it was recognized and script would run. Now Pi must boot and then I have to manually detach and reattach the USB cable in order for the script to run. This is not practical when monitoring the system remotely or if the Pi restarts due to power outage. Can this be corrected with software or is this a limitation of the hardware?

for this, you might want to switch to other device like an esp dev board or just raspberry pi. Having arduino connected via serial USB is not the best suited use case.
@adam any idea why it is not working.