- Posts: 28
 - Thank you received: 1
 
Please Log in or Create an account to join the conversation.
const String ESP8266_IP_ADDRESS = "172.28.1.201";
const String MODULE_ADDRESS = "N1S0"; 
public void Setup()
{  
  System.Diagnostics.Process.Start("CMD.exe","");
  
  EventHelper.ModuleChangedHandler((o, m, p) =>
    {
    Console.WriteLine(m.Domain +" "+ m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
 
      if (m.Domain == "Virtual" && m.Address == MODULE_ADDRESS && p.Property == "Sensor.DigitalValue")
        sendCommand(p.Value);
        
        return true;
    }); 
}
public void Run()
{
} 
private void sendCommand(string value)
{
  sendToServer("/gpio/"+value+"/1");
}
private void sendToServer(String message)
{
  try
  {
  //Console.WriteLine("TCP client command:" + message); 
   Int32 port = 80;
   System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient( ESP8266_IP_ADDRESS, port);
   Byte[] data = System.Text.Encoding.ASCII.GetBytes(message); 
   System.Net.Sockets.NetworkStream stream = client.GetStream();
   stream.Write(data, 0, data.Length);
   // Close everything.
   stream.Close();         
   client.Close();
  }
  catch(Exception e)
  {
    Console.WriteLine(e.StackTrace);
  }
}Please Log in or Create an account to join the conversation.