Turn off local server from app or from hardware


there is a way to turn off (send “sudo halt” command) to local rpi server either from the app or from the hardware?

i set a timeout if reached turn off the server and other hw power supply, but first i would like to halt the linux in a friendly manner.


Hi @wanek,
You can use VNC (using port forwading) and control the pi in a desktop environment.

yes, i know this, and already using putty and winscp while at home.

but the normal designation for this server is on the go, mounted on a special bike. i will have just phone and wemos, with no internet connection. i just need the server to use blynk, and for some data logging.

i set up the wemos so if the bike is not moving for x minutes, to turn off the power, to save batteries. but before the system is automagically is turning off, i would like to halt the server correctly, not just turn off the power every time.

Mmm…you can connect the WeMos to your smartphone while your PI is at home… Everything online. Have you considered this scenario?

i do not understand what you mean. maybe i didn’t explained well. so:

the wemos + pi zero w + phone all are equipped on the bike.

  • the zero w is the blynk server, otherwise i could not use blynk on areas without 3g
  • the wemos is controlling a stepper motor (for automated gear shifting), reads some sensors, etc.
  • the phone is needed to monitor the values in real time and also to change some parameters on the wemos

when the bike is stopped for more than 5 minutes, the wemos turns off the other hardware to conserve power, and enters in deep sleep. before the wemos cuts off the power of the pi, i would like to halt the pi correctly, to avoid corrupt files, etc.

What I think he ment is leave your pi at home. Setup a WiFi Hotspot on your phone and let the wemos connect to your pi server via your phone, as an alternative to bringing the pi with you

Which ofc does not work with this scenario :slight_smile:

I knew I was missing something…

Please, see below:

Pi Supply Switch - On/Off Power Switch for Raspberry Pi • Pi Supply

You can build something like this, it shouldn’t be complicated.

well, i’m interested in a software solution.
i’m certain that it is possible somehow to send a command especially for the server, or to tap the data which flows through the blynk server, and if a certain command is met, execute some script on the pi.

Second round…

Simple Raspberry Pi Shutdown Button


although this is also a hardware solution, but this seems applicable…
i could hook up a wire between the wemos and the pi, and pull that pin high on the wemos, turning off the pi this way.

That’s it! Little hardware interaction between your WeMos and the Pi…just two wires…

@wanek software solution is easy with Blynk’s javascript client but I’m not so sure how it would be done if you are using the C++ client.

how it would be done with js?

hm, but if i think better, the blynk server has to store the data somewhere, what is comming from the client. because if my phone is not started, i receive the values when i turn it on…
so, it could do the trick, to monitor with a script that file on the server, and if a specific value is found, execute a sudo halt command. @Costas, @Dmitriy , what do you think?

I would guess having both client and server on the pi would allow the use of bridge widget to send a shutdown command from wemos to the pi client where it handles the shutdown

yes, i considered this approach, but i would have to port all my arduino code to rpi, that would be a lots of work.

also, there are no analog pins on rpi, and i’m not sure how to handle the interrupts. again, too much complication and time.

if everything goes well, in the long term i would like to renounce completely to real time data monitoring and on the fly tweaks. than the blynk app and server wouldn’t be needed. only the wemos.

but currently, while testing and fine tuning the system i must see and control lots of parameters on the go. this is why i need blynk, because otherwise i can’t see and interact from my phone.

It would be done with shell_process but if you are using the WeMos then js is not directly available.

It could be done with the WeMos sending a signal to a web page on the RPi. This web page then shuts down the server. Blynk’s Webhook widget can be used to send a signal to a web page but there is a bit of homework for you to do to put it all together.

You can execute shell scripts with PHP I think, so in theory you could do a sudo halt from a PHP script, though it would probably violate every security rule in the book :slight_smile:

(php_exec or something like that).

thanks for the info!

i will look into those recommendations. regarding security, it has zero importance in this case, because only i will use this system, and even if someone would like to hack it, it has to be done while the bike is moving :smile: so, that would need a fit hacker on a bike to follow me, quite low probability combination…

1 Like