Welcome, Guest
Username: Password: Remember me

TOPIC: shutdown raspberry pi

shutdown raspberry pi 1 month 1 week ago #3779

  • nqdanyb
  • nqdanyb's Avatar
  • Offline
  • New Member
  • Posts: 3
  • Karma: 0
How to shutdown raspbian when a virtual button hit is pressed? please help me!
The administrator has disabled public write access.

shutdown raspberry pi 1 month 1 week ago #3780

  • EasyIoT
  • EasyIoT's Avatar
  • Offline
  • Administrator
  • Posts: 809
  • Thank you received: 252
  • Karma: 23
nqdanyb wrote:
How to shutdown raspbian when a virtual button hit is pressed? please help me!

Use EventHelper and System.Diagnostics.Process to execute command linux command shutdown.
The administrator has disabled public write access.
The following user(s) said Thank You: nqdanyb

shutdown raspberry pi 1 month 1 week ago #3781

  • nqdanyb
  • nqdanyb's Avatar
  • Offline
  • New Member
  • Posts: 3
  • Karma: 0
Thank you for the reply, i tried but it did not work. Here is my program:
/*
  This code is running one time when program is enabled
*/
public void Setup()
{
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
      // read switch status
      ModuleParameter par = ModuleHelper.GetProperty(Domains.VIRTUAL, "N1S0", "Sensor.DigitalValue");

      if (par.Value == "1")
      {
        System.Diagnostics.Process.Start("sudo shutdown -h now","");
      }
  return true;
    });


}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}
Sympathy for me because I am a new beginner
The administrator has disabled public write access.

shutdown raspberry pi 1 month 1 week ago #3782

  • EasyIoT
  • EasyIoT's Avatar
  • Offline
  • Administrator
  • Posts: 809
  • Thank you received: 252
  • Karma: 23
nqdanyb wrote:
Thank you for the reply, i tried but it did not work. Here is my program:
/*
  This code is running one time when program is enabled
*/
public void Setup()
{
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
      // read switch status
      ModuleParameter par = ModuleHelper.GetProperty(Domains.VIRTUAL, "N1S0", "Sensor.DigitalValue");

      if (par.Value == "1")
      {
        System.Diagnostics.Process.Start("sudo shutdown -h now","");
      }
  return true;
    });


}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}
Sympathy for me because I am a new beginner


To execute shudown code is more complicated (not tested):
System.Diagnostics.Process p1 = new System.Diagnostics.Process ();
      p1.StartInfo.UseShellExecute = false;
      p1.StartInfo.RedirectStandardOutput = true;
      p1.StartInfo.FileName = "sudo";
      p1.StartInfo.CreateNoWindow = true;
      p1.StartInfo.Arguments = "shutdown now";
      p1.StartInfo.RedirectStandardInput = true;
      p1.Start ();
The administrator has disabled public write access.
The following user(s) said Thank You: nqdanyb

shutdown raspberry pi 1 month 1 week ago #3783

  • nqdanyb
  • nqdanyb's Avatar
  • Offline
  • New Member
  • Posts: 3
  • Karma: 0
I do not know what else to say. Thanks for your support a lot. I tried it and it works great. Here is my code:
/*
  This code is running one time when program is enabled
*/
public void Setup()
{
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
      // read switch status
      ModuleParameter par = ModuleHelper.GetProperty(Domains.VIRTUAL, "N1S0", "Sensor.DigitalValue");

      if (par.Value == "1")
      {
        System.Diagnostics.Process p1 = new System.Diagnostics.Process ();
      p1.StartInfo.UseShellExecute = false;
      p1.StartInfo.RedirectStandardOutput = true;
      p1.StartInfo.FileName = "sudo";
      p1.StartInfo.CreateNoWindow = true;
      p1.StartInfo.Arguments = "shutdown -h now";
      p1.StartInfo.RedirectStandardInput = true;
      p1.Start ();        
      }
  return true;
    });


}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}
Thanks Again! Wish you always healthy and soon there will be new version of easyiot Server
The administrator has disabled public write access.
Time to create page: 0.127 seconds
Powered by Kunena Forum