Automation program

7 years 10 months ago - 7 years 10 months ago #3662 by essenemari
Replied by essenemari on topic Automation program
Hello,
just let you know: same server version like in my case (easyiot_v0_9.zip). If you are using "ready to go" "ESP8266 WiFi relay switch then one difference, in compare with my configuaration, is that you are using nodemcu... maybe it does matter... Did you try re-install easyiot server? Just thinking out loud.

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

7 years 10 months ago - 7 years 10 months ago #3666 by stefanovicpeter@gmail.com
hi, i already tried 0.8 version, also 0.9v and now i have 0.9b installed. it is the same. after power failure or RPI restart i still need to reenable automation program. in 0.9b version i have to enter into edit program script and click on update button. after that automation program runs. :-( i dont know what i have to do.

here is my code. after trigger on/off in easyiot im sending command to esp8266 relay to on or off
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.

Time to create page: 0.186 seconds

Forum latest

  • No posts to display.