I don’t think you even need to write a script. You can use a trigger that monitors the state of a pin and if it is high (or low) reboot the Pi.
Actually…looking back at what you want to do it’s probably a bad suggestion. If the Pi isn’t online it won’t receive the reboot command (facepalm) If someone else doesn’t beat me too it I’ll think up some python code to get you what you need.
Try this, I did some minimal testing but it should work. Edit the
rebootpin value to be the physical pin number you are connecting to your arduino.
import time import os import sys import RPi.GPIO as GPIO def reboot(channel): os.system("sudo reboot") rebootpin = 13 GPIO.setmode(GPIO.BOARD) GPIO.setup(rebootpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(rebootpin, GPIO.RISING, callback=reboot) while True: try: time.sleep(5) except (EOFError, SystemExit, KeyboardInterrupt): GPIO.cleanup() sys.exit()
If it works running it manually add it to your crontab with
crontab -e then type in the bottom
After much fiddle farting around, I was able to run the script but with no success. no reaction from pull up or pull down on pin16 I chose. when I exit python shell it indicates script running.shows ====restart==== maybe needs to be run on startup? hmmm.
It will work either way so if it doesn’t work when running it through a console it won’t work running it on boot. Try adding in some print statements to figure out where it’s failing. For example in the while loop add in a print to display the value of pin 16 and in the reboot function add in a print to tell you it actually made it there. If that doesn’t help let me know.
I added a “print GPIO” after gpio setup. Not sure what to put after the while statement to get the state of the pin. I tried print GPIO 18, print GPIO state, print GPIO status and mode etc but all ended in syntax error. I’m going to try Youtube see if anything takes.
Here it is print (reboot pin) gets a return of the correct pin
Module 'RPi.GPIO’from ‘/user/lib/python3/dust-packages/RPi/GPIO/init.py’>
Hey @rsiegel I have hit a wall on this. Not sure what print statement to use before while: after this print(rebootpin) give multiple prints of pin 16 so obviously rebootpin is set. On the blogs it was mentioned about rpi.GPIO versions. Could it be that I have an earlier version?
Should I start a new thread?
Hey @wmontg5988, I’m a little confused, what exactly are you trying to do?
You want an Arduino to be able to (from Cayenne) send a signal to the PI so you can remotely reboot it? Won’t the Arduino be on the same network and then unable to receive this command from Cayenne if you are unable to access the Pi? Or is the Arduino totally offline and just monitoring the Pi’s online state, ready to step in and reboot it if it determines the Pi is offline?
Apologies if I’m missing it in this thread or misunderstanding. I think once I have a clear idea of what you’re trying to accomplish I can offer a better suggestion.
Both the arduino and the rpi will have the setup to reset each other. I’ve never had a case of the network causing offline situations just the devices stop communicating for unknown reasons as has happened often lately. Losing control on the main device (rpi) could result in improper operation of the solar inverter. Once I get the PLCduino and rpi3 coded where I want them I can have my daughter upload the PLCduino and enter the python script. That will be the real test from here to the Philippines. I will pm my credentials so you can get and idea of what I’m trying to accomplish.
import time import os import sys import RPi.GPIO as GPIO def reboot(channel): print("rebooting now") os.system("sudo reboot") rebootpin = 13 GPIO.setmode(GPIO.BOARD) GPIO.setup(rebootpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(rebootpin, GPIO.RISING, callback=reboot) while True: try: print("Pin value: " + str(GPIO.input(rebootpin))) time.sleep(5) except (EOFError, SystemExit, KeyboardInterrupt): GPIO.cleanup() sys.exit()
Getting closer, moved print(" rebooting now ")under os.system(“sudo reboot”) indentation error. I now get pin value = 0 that seems promising. Calling RPi.GPIO as GPIO, is that using the RPi.GPIO index package to control the GPIO channels? I read where it may not be reliable if the CPU is prioritizing other tasks. I Might be asking it to do something it might never get around to?
Anyway I appreciate the help! Think I’ll take a break from it til I’ve got more time. Maybe study your script in more detail and see if I can cipher what’s going on.
Good Day! @adam,
I have finally gotten a script that works. I hunted forums and found this script which I placed on GitHub. I then had one last hurdle and that would be logging in after reboot. That easiest part, pi config select auto login, don’t know if that is secure tho. What do you think? You definitely sparked some learning with python, I am picking it apart to better understand what this script is doing. The forum at StackOverflow is where I found the script and a little adjustment was made as well adding the 3 statements found at the top of your script because it would not respond to GPIO input.
If it works then that’s good. Mine does the same thing with less features, reboot when the pin changes. Why do you need to log in after reboot? By default the standard Raspbian image should already do that.
When it reboots I was taken to the Rpi login screen asking for password. I’m sure the script I’m using probably has more than I need and if I don’t change the state of the input the appropriate number of times it will shut down instead of rebooting. If the cloud server is lagging behind I might not get the desired operation. I’m still trying to get my PLCduino to play but still working out the kinks with @kreggly help.I’m going to mess around with the script to see if I can get shutdown commented out and button presses down to 1. I think my fumbling around as a newbie I wasn’t able to get yours to work but I want to try yours again and see if I was running it wrong.
Hi, custom widgets are still coming soon. When will they be released?
Hi @fagallo79, apologies for the delays on these as our development priorities have taken us in other directions since some of the posts I made previously upthread. I’m tagging @bestes in case he has any visibility on potential date ranges for these. Out of curiosity, and to help us focus our development as we revisit this feature, which Custom Widget(s) were you most interested in?
I am in the Camera Widget
Yes, the camera widget (photo or video) would be great!
Hi and thanks for answer. I think that camera, map and lcd is the most interesting for my project.
However, I look forward to a password widget, a kind of 2 state button that needs to enter a code to change status. It’s most important.
I am waiting for news about it.
Cayenne is a fantastic system with endless possibilities !!!
in this project you may find what you are looking.CAYENNE Smart Home