ESPeasy and serial commands

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
cyclone
New user
Posts: 6
Joined: 06 Mar 2020, 12:43

ESPeasy and serial commands

#1 Post by cyclone » 01 Dec 2020, 17:27

Dears;

for my little project, I want my arduino to send data from a sensor to an ESP running ESPeasy (btw a wonderful stuff).

I checked the forum and found this way to do it, using serial communication :

- create a dummy device on the devices tab;
download/file.php?mode=view&id=5241
- in tools => advanced settings => enable serial port and set the baud rate;
download/file.php?mode=view&id=5242
- connect arduino and ESP using TX and RX;

- insert a simple sketch in arduino to send a value using Serial.print("TaskValueSet,1,1,123");

Code: Select all

void setup() {
  
Serial.begin(19200);

}

void loop() {

  Serial.print("TaskValueSet,1,1,123");
  delay(3000);

}
according the comments in the forum, with such a code, it's possible to send the value from the Arduino to the dummy device... but nothing is working on my side;

I tried also to connect directly the ESP with PUTTY, I can receive the log from the serial connection, but when I'm sending command, nothing happens...

Others checks must be activated in ESPEasy in order to allow the control of the ESP by the Arduino using serial communication ?
what is your feedback on this topic ?

many thanks for your help !
Attachments
Capture d’écran 2020-12-01 à 17.15.23.png
Capture d’écran 2020-12-01 à 17.15.23.png (49.26 KiB) Viewed 20107 times
Capture d’écran 2020-12-01 à 17.13.50.png
Capture d’écran 2020-12-01 à 17.13.50.png (49.21 KiB) Viewed 20107 times

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: ESPeasy and serial commands

#2 Post by ThomasB » 03 Dec 2020, 21:54

Your methods are correct. So perhaps there is something wrong with the ESP RXD input. Bad I/O pin, bad wiring, or bad evil spirits.

FWIW: A typical Arduino uses 5V logic levels. The ESP8266 is 3.3V. Some say that the ESP can tolerate 5V logic levels without harm. Others say it can be damaged by 5V signals in applications that omitted 5V<-->3.3V level translation circuitry. Regardless, if you can still successfully flash new firmware then I'd say no harm has occurred so far.

BTW, you can confirm your command statement by using ESPEasy's Tools Command entry box. For example, use your browser to submit the following and review the updated value:

Code: Select all

TaskValueSet,1,1,123
- Thomas

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

Re: ESPeasy and serial commands

#3 Post by TD-er » 04 Dec 2020, 01:02

In your Arduino sketch you're using a baud rate of 19200.
Is the same baud rate set in ESPEasy?

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: ESPeasy and serial commands

#4 Post by iron » 04 Dec 2020, 11:28

While on the serial commands subject, shouldn't "serialsend " be a standalone command enabled by default to be used in the rules w/o the need to enable Ser2Net task ?
-D

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

Re: ESPeasy and serial commands

#5 Post by TD-er » 04 Dec 2020, 11:57

You still need to have some setup like baud rate and I would also like to have the Ser2Net plugin being able to select what serial port to use. (still on my todo list)

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: ESPeasy and serial commands

#6 Post by iron » 04 Dec 2020, 13:19

TD-er wrote: 04 Dec 2020, 11:57 You still need to have some setup like baud rate and I would also like to have the Ser2Net plugin being able to select what serial port to use. (still on my todo list)
Could be variables ?

serialsend,'hello world',9600,8,none,1,s0

Just thinking out loud...
-D

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

Re: ESPeasy and serial commands

#7 Post by TD-er » 04 Dec 2020, 15:25

There are quite a few possible serial ports, so I don't think it is very practical to have them used as command arguments.
We have I2C to UART, HW serial, SW serial and on ESP8266 HW serial 0 in 2 versions.
On ESP32 you can give almost any GPIO pin along with naming a serial port.

So I rather have it in some kind of setup instead of command parameters.

This also allows to lock a port or at least add a warning if the same serial port is assigned for various use cases.
That's next to impossible if you allow it via command arguments.

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: ESPeasy and serial commands

#8 Post by iron » 05 Dec 2020, 09:07

Enable / Disable Serial port and Baud Rate settings are now located at : ip/advanced.
Perhaps the remaining settings shall go there as well ?
Unless you plan on more than 1 concurrent serial ports. In this case you will still need command argument for the serial port # ?
-D

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESPeasy and serial commands

#9 Post by Ath » 05 Dec 2020, 10:12

iron wrote: 05 Dec 2020, 09:07 Unless you plan on more than 1 concurrent serial ports. In this case you will still need command argument for the serial port # ?
That would be resolved once this PR#3198 is merged, allowing specific Tasks/Devices to be addressed by name or number.
/Ton (PayPal.me)

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

Re: ESPeasy and serial commands

#10 Post by TD-er » 05 Dec 2020, 13:34

@Ath
Not sure if this specific request is solved by then, as he suggests to make serialwrite an internal command, no longer part of a plugin/task.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESPeasy and serial commands

#11 Post by Ath » 05 Dec 2020, 13:51

Addressing several serial options would then be quite difficult, I guess, as each port/task can have its separate configuration. I don't think there is an easy way to store all these settings globally, as you can't know how many ports need to be configured. So leaving it in the plugin would then be a feasible solution.

If it has to go global, introducing 'serialselect,<port>' and 'serialconfig,<port>,<devicetype>,<baud>,<parity><databits>,<stopbits>...' internal commands, where port is a configuration index item (1..4 when allowing for 4 predefined ports, f.e.), could be a solution. These will have to pair up with the serialsend command, ofcourse.
/Ton (PayPal.me)

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

Re: ESPeasy and serial commands

#12 Post by TD-er » 05 Dec 2020, 20:17

Exactly for those reasons (and some more), I don't think it is a good idea to have it present as an internal command.
But I do see use cases where you may want to have several instances, so it still makes sense to have the task addressable commands as Ath's pending PR will add.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#13 Post by hereiam991 » 06 Dec 2020, 00:29

@cyclone
i just did something similar.
as mentioned take care that the baudrates on both devices are the same (should be clear, but can be forgotten eaisly).
on esp side standard is 115200.
i didnt had problem going with 115200 when only sending to the esb by using the taskvalueset command.
otherwise simply set the esp to 19200 as mentioned.

other problem i remember, make clear you end with a line termination, try to send the value in a with println.
i can see to post which arduino code worked in my case... i may posted it allready.

check whats comming out of the serial, connect a usb uart to the esp and open your serial monitor.
see if the line is terminated, not one long string.
if thats the case and your code is accoridng the taskvalueset example it should work, very reliable.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#14 Post by hereiam991 » 06 Dec 2020, 00:34

Code: Select all

 Serial.print("TaskValueSet,1,1");
Serial.println(variable);
  delay(3000);
something like this worked for me.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: ESPeasy and serial commands

#15 Post by ThomasB » 06 Dec 2020, 01:53

other problem i remember, make clear you end with a line termination, try to send the value in a with println.
Good catch; The OP's sketch example is missing the line termination. But he mentioned that Putty doesn't work either (receives log, but sent commands are ignored). At least we know baud rate is correct.

- Thomas

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

Re: ESPeasy and serial commands

#16 Post by TD-er » 06 Dec 2020, 11:48

I looked again at the screenshots posted in the opening post and indeed the serial settings appear to be correct.

How is the Arduino board connected to the ESP?
For example an Arduino board outputs 5V levels and the ESP 3v3.

What board is used for the ESP?
If it is a board with an onboard USB to serial then we also need to check if that one is still working or maybe fried by 5V levels.

Can you still flash the firmware from your PC to the ESP board?
If not then I think the USB to UART chip may be damaged and you never know what a damaged chip may do to the signal supplied on a pin.

Another test you may want to do is assigning a pulse counter task to the RX pin of Serial0 (GPIO-3 (D9)) and try sending data to the ESP. (disable "Use Serial" on tools->Advanced)
If that counter remains at 0, then either the RX pin on the ESP is damaged, or the bus may be held in a specific state or you may have a loose connection.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#17 Post by hereiam991 » 06 Dec 2020, 21:02

really seems baudrate isnt the problem.
in the setup are 19200 defined and the espeasy is set right, there shouldnt be more needed then enabling the serial port (to my limited knowledge of espeasy), which is also porpperly set in the picture.
as long the serial port of the esp is working, the arduino serial monitor should tell all what is needed.
hook up the esp, choose the right com port, serial monitor, and you should see what is spitted out.
if there is nothing, then its probably the hardware, btw i always used a LLC between 5V arduino and 3.3V ESP.
the advices above to check the hardware are very good and should tell you all.

"I tried also to connect directly the ESP with PUTTY, I can receive the log from the serial connection, but when I'm sending command, nothing happens..."
so we can asume RX and TX are connected right (RX to TX, vice versa), i just mention as it should be mentioned always.
this test at least told us that the TX line of the ESP should work, maybe your RX pin is really damaged by the 5V of the arduino ??

the line termination is really important and all started to work after i cared for it, rock solid.
but i always had datas on the serial port showing up, it just had been one endless string so nothing happened on the esp side.

btw i think i messed a comma in my code example above.
maybe thats better.

Code: Select all

 Serial.print("TaskValueSet,1,1,");
Serial.println(variable);
  delay(3000);

cyclone
New user
Posts: 6
Joined: 06 Mar 2020, 12:43

Re: ESPeasy and serial commands

#18 Post by cyclone » 08 Dec 2020, 10:27

Hello all;

in fact, i found the right way to do it.... so simple.... I'm so stupid indeed...

instead of :
Serial.print("TaskValueSet,1,1,Value");

we must use :
Serial.println("TaskValueSet,1,1,Value");

and this is working properly

Many thanks to all for your help

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#19 Post by hereiam991 » 09 Dec 2020, 03:02

great you figured it out.
how you get the value changing when its in between "123"?
honestly asking, cause i think in needed 2 lines to acomplish this.
fixed number is easy, but normally we want changinge values.

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

Re: ESPeasy and serial commands

#20 Post by TD-er » 09 Dec 2020, 19:56

hereiam991 wrote: 09 Dec 2020, 03:02 great you figured it out.
how you get the value changing when its in between "123"?
honestly asking, cause i think in needed 2 lines to acomplish this.
fixed number is easy, but normally we want changinge values.
You can just use some sprintf formatting or lots and lots of other options in C++ code :)

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#21 Post by hereiam991 » 10 Dec 2020, 05:42

got you!
didnt knew that commad tbh.
sadly a quick google search came up with this.
https://www.e-tinkers.com/2020/01/do-yo ... ing-point/
fine for ESP, not fine for arduinos, regarding floats.

well, its not so important for me, i was just wondering if i can get that in one line.
no big deal using 2 for it.

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

Re: ESPeasy and serial commands

#22 Post by TD-er » 10 Dec 2020, 10:44

I do love the elegance of oneliners, but it should not be a goal :)

What you can do (in Arduino code) is something like this:

Code: Select all

String formatted_val(floatvalue,3);
String full_text = "Output: #";
full_text.replace("#", formatted_val);
Serial.writeln(full_text);
But it is more efficient to do like this:

Code: Select all

Serial.write("Output: ");
Serial.writeln(String(floatvalue,3));
This way you have less memory allocations and no unused allocated memory remaining after the writing. (allocated until you leave the scope of the variables of course)

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESPeasy and serial commands

#23 Post by hereiam991 » 11 Dec 2020, 18:59

will try to wrap my head around that, thanks.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 35 guests