shutdown raspberry pi

1 year 4 months ago #3779 by nqdanyb
How to shutdown raspbian when a virtual button hit is pressed? please help me!

Please Log in or Create an account to join the conversation.

1 year 4 months ago #3780 by EasyIoT

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 following user(s) said Thank You: nqdanyb

Please Log in or Create an account to join the conversation.

1 year 4 months ago #3781 by nqdanyb
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

Please Log in or Create an account to join the conversation.

1 year 4 months ago #3782 by EasyIoT

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 following user(s) said Thank You: nqdanyb

Please Log in or Create an account to join the conversation.

1 year 4 months ago #3783 by nqdanyb
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

Please Log in or Create an account to join the conversation.

Time to create page: 0.540 seconds