Sending command to python

I use a raspberry pi with python code and I need the blynk app to send a command for reboot to python script. What i need to do this is:

  1. read the virtual pin
  2. put the pin’s number into a python variable
  3. use an “if” statement to run reboot
    I don’t know how to do steps one and two; anybody got the code?
    I checked the Blynk sketch, but they don’t say how to do it with python.

I’d run a cron job on the Pi that monitors a digital pin and if it’s in a certain state (HIGH lets say) then I’d run a sudo reboot command.
Use Blynk to set the pin HIGH, but don’t forget to set it LOW on reboot otherwise you’ll get into a constant reboot cycle.

Pete.

I need more help than that… I don’t know what cron is. I need what is listed in steps after my last edit.

I don’t use a Raspberry Pi as a client device and don’t use Python as a programming language.
I was simply telling you the direction I would take if I had this requirement.

If you google cron then you’ll see what it is.

The use of cron and the use of the reboot command issued by the sudo user are Blynk specific, so there will be plenty of examples of how to do this. The only Blynk element in the process is to set a digital pin to a predetermined state so that your cron task can detect this and perform the reboot.

If you’re not keen on this approach then I’m sure that there are many other ways you could do it, either directly or using a slave MCU to perform the reboot for you.

Pete.

thanks for trying, could you share this question to someone that might have the answer? That is if you know anyone. No pressure. :slight_smile:

Sorry to be a downer, but cron isn’t what I need.

You’ve done that by posting it here, but I’d still recommend doing a little searching oif you own, there are lots of examples out there about how to monitor a Pi GPIO and reboot f it’s pulled HIGH or LOW.

Pete.

I already have a python scheduler. :slight_smile:

Thanks I’ll try to search, but it is complicated when no tutorials exist for this. :confused:

I figured it out, here is the code needed:
import blynklib

BLYNK_AUTH = ‘’

initialize Blynk
blynk = blynklib.Blynk(BLYNK_AUTH)

WRITE_EVENT_PRINT_MSG = "[WRITE_VIRTUAL_PIN_EVENT] Pin: V{} Value:

register handler for virtual pin V4 write event
@blynk.handle_event(‘write V4’)
def write_virtual_pin_handler(pin, value):
print(WRITE_EVENT_PRINT_MSG.format(pin, value))
import os
os.system(“reboot”)
###########################################################
#infinite loop that waits for event
###########################################################
while True:
blynk.run()

Please post the code with triple back ticks on a separate line before and after your code. ```