× This is the optional category header for the Suggestion Box.

Add TCP *Relay node* (esp8266 only needed)

9 years 2 months ago #607 by cdj

cdj wrote: Last question but interesting. Have you seen esphttpd project flashing the esp? if you implement this we can make a node only with esp and relay without arduino !

EasyIoT wrote: 9. Good idea, maybe someone will implement EasyIoT library on ESP8266 module :)

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

9 years 2 months ago #608 by EasyIoT

VasilijHCN wrote: Yes, U are right. This will be great, to control simple relay without arduino.


Try this. Add virtual module and then add virtual module to group. Change module type to digital output. Remember module address. Then go to automation part and copy program below. Change ESP IP address, virtual module address and GPIO pin correspondingly. Enable automation program and go in WEB interface. Switch ON and OFF virtual module and see ESP8266 controlling GPIO pin without Arduino :)
const String ESP8266_IP_ADDRESS = "102.168.1.5";
const String ESP_GPIO = "00";

/*
  This code is running one time when program is enabled
*/
public void Setup()
{
  
  	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 == "N1S0" && p.Property == "Sensor.DigitalValue")
        	sendCommand(ESP_GPIO, p.Value);
        
        return true;
    });

}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}
                


private void sendCommand(string pin, string value)
{
  sendToServer("GPIO,"+pin+","+value);
}



private void sendToServer(String message)
{
  try
  {
  Console.WriteLine("TCP client command:" + message);
  
   Int32 port = 9999;
   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);
  }
}
The following user(s) said Thank You: cdj, VasilijHCN

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

9 years 2 months ago #610 by cdj
This is fantastic, but esp ip address is not static. This can work only if we assign static address to esp mac from router (if it can be possible).
No way to fix this i suppose....

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

9 years 1 month ago #619 by VasilijHCN

EasyIoT wrote:

VasilijHCN wrote: Yes, U are right. This will be great, to control simple relay without arduino.


Try this. Add virtual module and then add virtual module to group. Change module type to digital output. Remember module address. Then go to automation part and copy program below. Change ESP IP address, virtual module address and GPIO pin correspondingly. Enable automation program and go in WEB interface. Switch ON and OFF virtual module and see ESP8266 controlling GPIO pin without Arduino :)
const String ESP8266_IP_ADDRESS = "102.168.1.5";
const String ESP_GPIO = "00";

/*
  This code is running one time when program is enabled
*/
public void Setup()
{
  
  	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 == "N1S0" && p.Property == "Sensor.DigitalValue")
        	sendCommand(ESP_GPIO, p.Value);
        
        return true;
    });

}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
}
                


private void sendCommand(string pin, string value)
{
  sendToServer("GPIO,"+pin+","+value);
}



private void sendToServer(String message)
{
  try
  {
  Console.WriteLine("TCP client command:" + message);
  
   Int32 port = 9999;
   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);
  }
}

Thank U !!! All working perfect :woohoo:

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

9 years 1 month ago - 9 years 1 month ago #620 by VasilijHCN
How about a RGB(or single) LED Dimmer ?
www.esp8266.com/viewtopic.php?f=19&t=102...1&hilit=dimmer#p9041
This stuff also use tcp server, working on LUA firmware.
Also trying this in web browser:
http://192.168.1.105:88/Api/EasyIoT/Control/Module/Virtual/N5S0/ControlLevel/35
No change in the virtual N5S0 temperature node.

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

9 years 1 month ago #627 by EasyIoT

VasilijHCN wrote: How about a RGB(or single) LED Dimmer ?
www.esp8266.com/viewtopic.php?f=19&t=102...1&hilit=dimmer#p9041
This stuff also use tcp server, working on LUA firmware.
Also trying this in web browser:
http://192.168.1.105:88/Api/EasyIoT/Control/Module/Virtual/N5S0/ControlLevel/35
No change in the virtual N5S0 temperature node.


You can build dimmer. It's very easy to modify switch program.

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

Time to create page: 0.319 seconds

Forum latest

  • No posts to display.