send command via UDP message

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Swallowtail
New user
Posts: 4
Joined: 19 Dec 2018, 08:34

send command via UDP message

#1 Post by Swallowtail » 19 Dec 2018, 08:42

Hi guys,

I’m new to ESP Easy and have succesfully flashed my first Sonoff S20 a couple of days ago. Things went pretty good and I can send commands via http get.

However I would rather use UDP to send commands. I activated and configured “UDP Generic”.

I tried to send lots of different UDP messages vial netcat but so far no success. Unfortunately the UDP interface is not documented very well.

Can anybody show me an example on how to send commands via UDP (e.g. something corresponding to http://<espeasyip>/control?cmd=gpio,12,1)

Thanks!

Cino2424
Normal user
Posts: 17
Joined: 30 Sep 2018, 16:35

Re: send command via UDP message

#2 Post by Cino2424 » 19 Dec 2018, 12:06

I think I have a device which sends UDP Messages, I can look later at work if this is correct.

Swallowtail
New user
Posts: 4
Joined: 19 Dec 2018, 08:34

Re: send command via UDP message

#3 Post by Swallowtail » 19 Dec 2018, 12:16

That would be great. Just so there is no misunderstanding I can have the ESP Easy Unit send messages just fine via rules (e.g. SendToUDP 192.168.1.8,5128,Relay_State:[Relay#Switch])

I just can’t control it.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: send command via UDP message

#4 Post by grovkillen » 19 Dec 2018, 14:02

Code: Select all

SendTo,<unit nr>,<command>
The UDP don't care about IP address. Use the unit number only.

Command syntax is just like any other command.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Swallowtail
New user
Posts: 4
Joined: 19 Dec 2018, 08:34

Re: send command via UDP message

#5 Post by Swallowtail » 19 Dec 2018, 14:27

For example I send the following from my linux machine:

Code: Select all

echo "SendTo,1,gpio,12,1" | nc -u -c 192.168.1.22 5700
192.168.1.22 is the IP of the Easy ESP unit and 5700 the port specified in the Generic UDP controller.

This does nothing unfortunately.

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: send command via UDP message

#6 Post by FanOfHue » 19 Dec 2018, 15:05

Because of my Message Bus project, i happen to know more about the UDP protocol used in ESP Easy.
The controller is only used to send data.

But ESP Easy listens to UDP if a port is set in advanced settings.

Look at this code in networking.ino:

Code: Select all

          if (!PluginCall(PLUGIN_WRITE, &TempEvent, request))
            ExecuteCommand(VALUE_SOURCE_SYSTEM, &packetBuffer[0]);
You can just send any string to the IP and port of that ESP Easy unit and it should process it.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: send command via UDP message

#7 Post by grovkillen » 19 Dec 2018, 15:11

Try using the command line in tools.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Swallowtail
New user
Posts: 4
Joined: 19 Dec 2018, 08:34

Re: send command via UDP message

#8 Post by Swallowtail » 19 Dec 2018, 15:31

Again - do not want to send commands between 2 ESPs. I want to send commands from my computer (home automation) to the ESP via UDP.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: send command via UDP message

#9 Post by grovkillen » 19 Dec 2018, 16:39

Swallowtail wrote: 19 Dec 2018, 15:31 Again - do not want to send commands between 2 ESPs. I want to send commands from my computer (home automation) to the ESP via UDP.
But, the command is P2P for ESP2ESP...
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: send command via UDP message

#10 Post by enesbcs » 19 Dec 2018, 17:12

Swallowtail wrote: 19 Dec 2018, 15:31 Again - do not want to send commands between 2 ESPs. I want to send commands from my computer (home automation) to the ESP via UDP.
I think you can send a simple UDP package to the ESP, _if you know the target's IP address_, to the port, that you have set in Tools/Advanced settings. But i do not see why it is better, than sending by a HTTP command? (the ESPEasy devices advertises itself and knew each other IP address by UDP broadcasting, this is how P2P works)

Anyway the UDP package only needs to contain the command - as a zero terminated string - and the netcat utility can be used to send it.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: send command via UDP message

#11 Post by enesbcs » 19 Dec 2018, 17:33

grovkillen wrote: 19 Dec 2018, 16:39
Swallowtail wrote: 19 Dec 2018, 15:31 Again - do not want to send commands between 2 ESPs. I want to send commands from my computer (home automation) to the ESP via UDP.
But, the command is P2P for ESP2ESP...
Maybe it will change in the soon future.. i am currently trying to understand the ESPEasy P2P Networking packages and i found this structure:

Code: Select all

struct C013_SensorDataStruct
{
  byte header = 255;
  byte ID = 5;
  byte sourcelUnit;
  byte destUnit;
  byte sourceTaskIndex;
  byte destTaskIndex;
  float Values[VARS_PER_TASK];
};
But according to my tests (using the 2018.12.04 build) i've got this:

Code: Select all

SENSORDATA RAW b'\xff\x05\x00\x01\x05\x05\x00\x00\x00\x00\x80?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@'
SENSORDATA UNPACKED (255, 5, 0, 1, 5, 5, 0, 0, 1.0, 0.0, 0.0, 2.0)
This means, that after destTaskIndex and before floats there are two bytes with zeroes... (1.0 is Value1 and 2.0 is Value4 of a Dummy variable) what is this 2 bytes for?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: send command via UDP message

#12 Post by TD-er » 19 Dec 2018, 19:37

The current implementation of the P2P protocol is documented:
https://espeasy.readthedocs.io/en/lates ... /C013.html

Yes it will change, but the change will be an addition. It will still be backwards compatible with existing protocol.
Later I will add an option to disable the "old" (current) p2p implementation, since there is no security at all in the current protocol.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: send command via UDP message

#13 Post by enesbcs » 19 Dec 2018, 20:42

TD-er wrote: 19 Dec 2018, 19:37 The current implementation of the P2P protocol is documented:
https://espeasy.readthedocs.io/en/lates ... /C013.html

Yes it will change, but the change will be an addition. It will still be backwards compatible with existing protocol.
Later I will add an option to disable the "old" (current) p2p implementation, since there is no security at all in the current protocol.
Thank you, i see.
How can i get a NodeTypeID for my "RPI Easy" project? :) For example 129 is usable? Or do you have any plan on further NodeTypes or any logic behind the numbering scheme?
1 = “ESP Easy” b00000001
17 = “ESP Easy Mega” b00010001
33 = “ESP Easy 32” b00100001
65 = “Arduino Easy” b01000001
81 = “Nano Easy b01010001

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: send command via UDP message

#14 Post by TD-er » 19 Dec 2018, 21:31

I don't know the number-schema.
I just documented it.
Looks like somebody was thinking about some simple mask to maybe send messages to some types and exclude others.
But then the "Nano Easy" is a bit (pun intended) strange.
I would say 9 and 5 are also still available :)
Maybe 129 could cause issues if some implementation is using an int8 instead of a uint8.

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: send command via UDP message

#15 Post by FanOfHue » 20 Dec 2018, 08:11

TD-er wrote: 19 Dec 2018, 19:37 The current implementation of the P2P protocol is documented:
https://espeasy.readthedocs.io/en/lates ... /C013.html

Yes it will change, but the change will be an addition. It will still be backwards compatible with existing protocol.
Later I will add an option to disable the "old" (current) p2p implementation, since there is no security at all in the current protocol.
Hello TD-er

Nice to have this level of documentation. I didn't know that this was available. I had to reverse engineer the code to figure out the internal protocol.

I've also tried to think of a more enhanced package structure for the UDP protocol, but in the end i thought that the "topic" concept of MQTT would be more than sufficient to build a sensor/actuator/controller network. I'm currently working on my personal message bus, based on simple UDP text messages.

I have recently started to use several repositories from letscontrolit.com and converted those to support the UPD text messaging. I can't tell if it's really stable on this short term, but it is running on following platforms at the moment in my mini test setup:
  • Arduino Nano with ENC28J60 ethernet shield
  • Arduino Mega 2560 with W5100 ethernet shield
  • ESP8266 with ESP Easy and MessageBus plugin
  • ESP8266 with Core edition
  • ESP32 with Core edition
  • Windows 10 with C# edition of the ESP rule engine
It should also be easy to implement a rule engine with UPD messaging on platforms like RaspBerryPI or other Linux platforms. But i don't have those and my Linux knowledge is zero.

Messaging is simple topic based single values like:

Code: Select all

Outdoor/Temperature=8.5
Outdoor/Lux=23500
HueGW/Hallway/Motion=1
The nodelist is maintained on specific messages:

Code: Select all

MSGBUS/Hostname=xxxxx
I don't know if anyone would be interested in this message bus idea, but i like the concept of platform independent Home Automation messaging with such a low footprint that it can also work on very limited devices like the classic Arduino Uno or Nano. It can also be used without a central message broker. So i could provide two devices to someone and they would be able to maintain their two-node network without any centralized setup.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: send command via UDP message

#16 Post by grovkillen » 20 Dec 2018, 08:14

The concept of a headless system is 100% within our projection of the project. So these inputs are really nice to see. Thanks!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: send command via UDP message

#17 Post by FanOfHue » 20 Dec 2018, 10:57

Swallowtail wrote: 19 Dec 2018, 08:42 Hi guys,

I’m new to ESP Easy and have succesfully flashed my first Sonoff S20 a couple of days ago. Things went pretty good and I can send commands via http get.

However I would rather use UDP to send commands. I activated and configured “UDP Generic”.

I tried to send lots of different UDP messages vial netcat but so far no success. Unfortunately the UDP interface is not documented very well.

Can anybody show me an example on how to send commands via UDP (e.g. something corresponding to http://<espeasyip>/control?cmd=gpio,12,1)

Thanks!
Using an udp send tool on my Windows PC:

Code: Select all

udpsend 192.168.0.118 65500 reboot
will reboot the target ESP Easy unit! (if port 65000 has been set in advanced settings). You can send this UDP message from any device!

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: send command via UDP message

#18 Post by FanOfHue » 20 Dec 2018, 11:00

grovkillen wrote: 20 Dec 2018, 08:14 The concept of a headless system is 100% within our projection of the project. So these inputs are really nice to see. Thanks!
Doesn't "headless" mainly refer to systems without monitor/keyb/mouse?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: send command via UDP message

#19 Post by grovkillen » 20 Dec 2018, 11:03

FanOfHue wrote: 20 Dec 2018, 11:00
grovkillen wrote: 20 Dec 2018, 08:14 The concept of a headless system is 100% within our projection of the project. So these inputs are really nice to see. Thanks!
Doesn't "headless" mainly refer to systems without monitor/keyb/mouse?
True, but in my analogy I mean controller-less 8-)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: send command via UDP message

#20 Post by FanOfHue » 20 Dec 2018, 11:38

I see, then we are on the same track.

I've been working with Arduino microcontrollers for quite some time and build up a nice collection of hardware that is still in use around the house. I could start to replace them all with ESP32 but that would be the easy way out. These Arduino boards have served me well for many years and do not deserve to be tossed into the bin without good reason. Never had any controller in use.

I have a garden shed, UTP connected and out of Wifi range that uses an Arduino Nano with an ENC26J80 ethernet shield with a simple http sketch. I actually lost that particular source code so i was thinking of a way to integrate ESP Easy with other nodes to have some sort of message bus controlled environment.

I noticed that a NanoEasy sketch already existed on LetsControlIt github so i used that a starting point. The current NanoEasy does not support a rule engine so i implemented a tiny one. It was a real challenge to get things going into 32k of progmem and 2k of RAM but it's currently running with my Message Bus support and a core web interface with two rule based control buttons:

boot.txt:

Code: Select all

on System#Config do
  config,debug,1
  config,mac,123
  config,network,192.168.0.254
  config,name,_NanoCore
  config,port,65501
endon
rules.txt

Code: Select all

on System#Boot do
  valueSet s,0,0
endon

on D_ON do
  gpio 7,1
  gpioState s,7
  msgbus Shed/Light=1
endon
on D_OFF do
  gpio 7,0
  gpioState s,7
  msgbus Shed/Light=0
endon

on System#Web do
  webPrint <h1>Power %s%</h1>
  webButton button-link;/control?cmd=event,D_ON;On
  webButton button-link;/control?cmd=event,D_OFF;Off
endon
NanoCore.png
NanoCore.png (3.89 KiB) Viewed 13752 times
All powered by Arduino Nano and ENC26J80!

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: send command via UDP message

#21 Post by enesbcs » 29 Dec 2018, 22:02

TD-er wrote: 19 Dec 2018, 21:31 I don't know the number-schema.
I just documented it.
Looks like somebody was thinking about some simple mask to maybe send messages to some types and exclude others.
But then the "Nano Easy" is a bit (pun intended) strange.
I would say 9 and 5 are also still available :)
Maybe 129 could cause issues if some implementation is using an int8 instead of a uint8.
Thank you, can i claim for "5" to RPIEasy?

Code: Select all

NODE_TYPE_ID_RPI_EASY_STD        =   5

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests