Wemos D1 I2C Befehl senden

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Wemos D1 I2C Befehl senden

#1 Post by Adrian08642 » 15 Sep 2020, 18:18

Hallo,

Ich bin noch neu hier, bitte seid gnädig :)

Also die Idee ist über FHEM einen Wemos D1 (auf dem ESPEasy läuft) anzusteuern und dieser sendet über I2C zu einem Arduino Nano z.B. eine Integer Zahl.
Am besten wäre es wenn der Wemos auch intervallweise eine Statusabfrage startet.

Hat da jemand von euch eine Idee wie man das umsetzt?

Gruß Adrian

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

Re: Wemos D1 I2C Befehl senden

#2 Post by TD-er » 15 Sep 2020, 18:25

There is no "generic I2C plugin", but if you can use some UART protocol then maybe ser2net plugin may be useful here?

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#3 Post by Adrian08642 » 28 Sep 2020, 14:11

I found that https://github.com/letscontrolit/ESPEasy/issues/2344, is it possible to finish the request?

Alternative: How can use the UART, I didn't found that plugin (Ser2Net)?

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

Re: Wemos D1 I2C Befehl senden

#4 Post by TD-er » 28 Sep 2020, 14:25

Depends on what you need.

For example there is the "ser2net" plugin.
See this (dated and limited) description on the Wiki: https://www.letscontrolit.com/wiki/index.php/Ser2Net

If you only need to receive strings from the connected device and occasionally send some (ASCII) lines terminated with a line ending, then you can also try the (experimental) P087 SerialProxy.
This plugin allows to receive ASCII strings (terminated with a line ending) and send them to a connected MQTT controller.

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#5 Post by Adrian08642 » 28 Sep 2020, 14:38

Ok, the plugin P087 sounds promising. How do I install this on my Wemos D1. Neither ser2net nor P087 is listed under Task Settings -> Device. Overall, there are very few plugins.

Thanks for your help :)
Attachments
Screenshot 2020-09-28 143805.jpg
Screenshot 2020-09-28 143805.jpg (256.2 KiB) Viewed 4914 times

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

Re: Wemos D1 I2C Befehl senden

#6 Post by TD-er » 28 Sep 2020, 14:54

Due to its expermental stage, it is not included in the regular builds, but I guess it may be in the "custom" builds that are included in the nightly builds.

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#7 Post by Adrian08642 » 28 Sep 2020, 15:01

Where can I find the nightly builds? Or if I have the .ino how can I install / load it?

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

Re: Wemos D1 I2C Befehl senden

#8 Post by TD-er » 28 Sep 2020, 15:04

See here for the nightly builds: https://github.com/letscontrolit/ESPEasy/releases

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#9 Post by Adrian08642 » 28 Sep 2020, 15:06

Ok there is the _P087_SerialProxy.ino how can I load it?

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

Re: Wemos D1 I2C Befehl senden

#10 Post by TD-er » 28 Sep 2020, 15:10

Have you looked into the ZIP files, where all the bin files are?
You need to flash a bin file and then look into the plugin list to see if it is there.

I just looked into the ZIP file of the last build and the custom build doesn't include this plugin.

What build size (flash size) do you need, I can make a test build for you.
What is the filename of the bin you currently have flashed?

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#11 Post by Adrian08642 » 28 Sep 2020, 15:26

How do I see in the BIN file whether the plugin is included (where is the plugin list)?
I have ESP_Easy_mega_20200812_normal_ESP8266_4M1M flashed this version.

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

Re: Wemos D1 I2C Befehl senden

#12 Post by TD-er » 28 Sep 2020, 15:46

Here is the plugin list, but it is not 100% accurate anymore as the last few plugins are not all included in the "test" builds.
https://espeasy.readthedocs.io/en/lates ... al-plugins

Problem is we're simply running out of space on the flash, so there must be a new set definition of plugins per build, or a build environment where someone only has to click the plugins needed.

I just made a test build for you including the P087 serial proxy plugin
https://www.dropbox.com/s/1afyc9wrdxeku ... M.bin?dl=0

But remember, it is highly experimental.
The command for this plugin to write something to it is "serialproxy_write"

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#13 Post by Adrian08642 » 03 Oct 2020, 16:53

How I define a new set of plugins. How I get the BIN file by my self?

Your BIN file is working fine, but how do I get the plugin to work? Is there any documentation here?

Thanks for all your help

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

Re: Wemos D1 I2C Befehl senden

#14 Post by TD-er » 04 Oct 2020, 10:26

Of course there is some documentation on that (although it could be improved as this is a frequently returning question)

For using PlatformIO: https://espeasy.readthedocs.io/en/lates ... ormIO.html
For using Arduino IDE: https://espeasy.readthedocs.io/en/lates ... noIDE.html

IMHO the preferred way is PlatformIO, but there are lots of users to disagree with me.

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#15 Post by Adrian08642 » 04 Oct 2020, 14:34

ok I think that is the answer for the question "How I build my own BIN file". Thanks for that.

But I can't get the plugin to run. The Command "http://<espeasyip>/control?cmd=serialproxy_write,5" is doing nothing.
Can you help me with that problem?

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

Re: Wemos D1 I2C Befehl senden

#16 Post by TD-er » 04 Oct 2020, 15:26

What is not working?
Remember the "serialproxy_write" does write the literal string including a line termination (CRLF) to the serial port.

So it does not send the byte 5, but the characters "5<CR><LF>"

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#17 Post by Adrian08642 » 06 Oct 2020, 08:10

If I type in the command it says:

Unknown or restricted command!

sending the character "5<CR><LF>" would be fine for the first step.

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

Re: Wemos D1 I2C Befehl senden

#18 Post by TD-er » 06 Oct 2020, 13:26

From where do you send the command?

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#19 Post by Adrian08642 » 08 Oct 2020, 11:59

Ok I don't know what I did differently this time, but now the command is working.

How I can receive data?

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

Re: Wemos D1 I2C Befehl senden

#20 Post by TD-er » 08 Oct 2020, 12:32

You can feed the received strings to an MQTT controller.
Currently the "String" type of data is not yet supported in a lot of places in ESPEasy.
It can be used to send to a MQTT controller, but it is also possible to send it to a display ("[task#varname]" also supports strings) or use it in rules to send to an HTTP server in an URL.

It is not yet possible to compare strings in rules, but you can create substrings and if you know the characters at some position in a line will be numerical you can convert them to an int.
This can even be done if you receive HEX data.

See:
- https://espeasy.readthedocs.io/en/lates ... #substring
- https://espeasy.readthedocs.io/en/lates ... ing#strtol

Adrian08642
Normal user
Posts: 11
Joined: 15 Sep 2020, 18:14

Re: Wemos D1 I2C Befehl senden

#21 Post by Adrian08642 » 09 Oct 2020, 12:41

First of all thanks for all your help and time :)

To be concrete with my problem:
I'm sending with an Arduino a number (803) to the ESPeasy. In the end, I need the number on my FHEM Server.


At the moment I don't know where I receive the message on the ESPeasy.
How can I send on the number to the FHEM server?
If I have to config the Serial Proxy receives rules.

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

Re: Wemos D1 I2C Befehl senden

#22 Post by TD-er » 09 Oct 2020, 13:33

Not tested it, but I guess you could do something like this in the rules.

Assume the task running serialproxy is called "proxy" and the value it returns is "v"
So you may need to change that to match your setup.

The idea is to store the received value in a dummy task at task 3, variable 1 (you may need to change that too)

Code: Select all

on [proxy#v] do
  taskvalueset,3,1,[proxy#v]
endon

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

Re: Wemos D1 I2C Befehl senden

#23 Post by Ath » 09 Oct 2020, 17:10

You might want to remove the square brackets from the line with 'on ... do'
/Ton

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

Re: Wemos D1 I2C Befehl senden

#24 Post by TD-er » 09 Oct 2020, 20:27

Ath wrote: 09 Oct 2020, 17:10 You might want to remove the square brackets from the line with 'on ... do'
Aren't they removed in the parser to find the on...do line?

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

Re: Wemos D1 I2C Befehl senden

#25 Post by Ath » 10 Oct 2020, 10:20

I would expect the [device#variable] to be replaced by the current sensor value, so, no event would trigger that piece of code?
/Ton

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

Re: Wemos D1 I2C Befehl senden

#26 Post by TD-er » 10 Oct 2020, 12:43

Ath wrote: 10 Oct 2020, 10:20 I would expect the [device#variable] to be replaced by the current sensor value, so, no event would trigger that piece of code?
Hmm good point... I thought that was why it stripped off the square brackets first, but may have to check in the code if that's still the current situation here.

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

Re: Wemos D1 I2C Befehl senden

#27 Post by hereiam991 » 19 Nov 2020, 12:21

i hope its ok to repoen this thread.
also i hope some can give me some pointers.

i do want to send a value (or 2, in fact co2 and temp) to a arduino by using the hardware serial.

i have never worked with the rules set of espeasy so forgive my stupidness.

as i understood one way to achieve my goal would be.

using the serial proxy with "serialproxy_write".
-setup a dummy device, forware the values to this device by a rule.
-in the newly created device we use "serialproxy_write" on every update or may every second or 2 periodically.

is there any example written somewhere?

i found these.
https://www.letscontrolit.com/wiki/inde ... rial_Rules
but there is no specific example for "serialproxy".

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

Re: Wemos D1 I2C Befehl senden

#28 Post by hereiam991 » 19 Nov 2020, 18:48

have played around a bit to get a better picture.
maybe i could filter the output.
just havent found the any usable log entry/setting so far.

basically i just need the CO2 value, the temp reading of the mhz19b sensor seems unsuable anyway and its not important.

is there any precompiled version offering the serialproxy as also the normal plugins?, i would need the dummy devices as the mh-z19b, a bme280 gy7021 maybe also (so nothing too fancy needed).
otherwise i prob have to compile myself, just wanna ask if there is something ready.

other question would be, is there maybe a commnad i could send from the arduino to request a value from the esp8266 (co2) and it get publsihed by serial or at least show up in some log entry?

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

Re: Wemos D1 I2C Befehl senden

#29 Post by TD-er » 19 Nov 2020, 19:37

Right now there is no ready made build including all those plugins.
You can just send data from an Arduino to the ESP via serial, like any command that's present in ESPEasy. See: https://espeasy.readthedocs.io/en/lates ... mmand.html
As long as the "Enable Serial port" (Tools => Advanced) is enabled.

Right now we don't have a command to fetch, but I guess you may try to send a command like this:

Code: Select all

logentry,"Bla [temp2#T1]"
This will show something like this:

Code: Select all

346701 : Info   : Bla 22.19
N.B. "temp2" is a Dallas sensor task at my node and "T1" is the first temperature variable name.
I added some marker "Bla" so you could try to filter out the values.

This is all part of any build, so you don't need to make your own to get this.
Just make sure you're logging with loglevel "info" to the serial port.

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

Re: Wemos D1 I2C Befehl senden

#30 Post by hereiam991 » 19 Nov 2020, 22:09

thats very helpfull, esspecially with the code example.
i will try tomorrow after some sleep.

i do have my values send to the espeasy from the arduino by using the taskvalueset command and this is working flawless with a half dozen values at 115200baud.

it should be doable to fish the value from the log, its really just one so far, good to learn a bit.

and thanks again for the detailed explanation, also for naming the log level.

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

Re: Wemos D1 I2C Befehl senden

#31 Post by hereiam991 » 21 Nov 2020, 03:14

your hint where very helpfull.
i can now receive my co2 value on the arduno by filtering the data from the info log.

if its any help to someone.
my Rule:

Code: Select all

on CO2#ppm do
logentry,"| [CO2#ppm] $"
endon
my Arduino code:

Code: Select all

boolean newData = false;
int co2 = 0;

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

void loop() {
recvWithStartEndMarkers();
  //showNewData();}
  }
  
  void recvWithStartEndMarkers() {
  const byte numChars = 64;
  char receivedChars[numChars];
  boolean newData = false;
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '|';
  char endMarker = '$';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
  co2 = 0;
  co2 = atoi(receivedChars);
}

void showNewData() {
  if (newData == true) {
    Serial.print("This just in ... ");
    //    Serial.println(receivedChars);
    newData = false;
  }
}
based on these examples
https://forum.arduino.cc/index.php?topic=288234.0

its working ok, but i needed to go down with the baudrate, just sending with the arduino is possible with 115200 baud.

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

Re: Wemos D1 I2C Befehl senden

#32 Post by TD-er » 21 Nov 2020, 10:39

You can set the baud rate on the Tools => Advanced page

I think it will be best to either make the SerialProxy plugin a bit more user friendly, or make a command to actually send data to the serial port (just any serial port)
N.B. this is a mental ToDo for me :)

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

Re: Wemos D1 I2C Befehl senden

#33 Post by hereiam991 » 21 Nov 2020, 11:10

a real command would be very helpfull, while it looks i got away with this aproach, icould i magine this solution could fail in more complex scenarios.

i am using a lower baudrate allready atm 19200.
i would need to make more and longer tests to determine what really works.
could be i still had some unecessary garbage on the serial from the arduino, i need another testrun, will report what baud i could achieve.
may can push it higher now, 38k baud maybe.
9600 is quite safe, obviously, 19200 is fine too (even with a little unnecesaary garbage on the serial).
i also increased the receive buffer from 32 to 64, this seemed to help too.
Last edited by hereiam991 on 21 Nov 2020, 11:24, edited 1 time in total.

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

Re: Wemos D1 I2C Befehl senden

#34 Post by TD-er » 21 Nov 2020, 11:22

Keep in mind that lowering the baud rate will also delay the output of all logs.
The logs can sometimes be quite verbose and at lower baudrate the buffers for the log may fill up the memory.
There are some checks to throw out messages if the buffer fills up all memory, but this also means the message you try to send may get lost or at least delayed.
It is even possible a message may be cut off half way if the memory runs low.

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

Re: Wemos D1 I2C Befehl senden

#35 Post by hereiam991 » 22 Nov 2020, 20:41

i am testing today with 57600 baud and it seems to be ok after i cleaned the garbage, thinking 38400 should be kinda safe.
i also rasied the buffer of the receiving arduino to 128 byte.
think i saw him once skipping a beat, but overall it not so unstable and prbalby usable for just displaying a value.

edit: back to 19200 and wil see, think its more stable.
thinking of it, a "taskvalueget" command would kinda nice to have.
like the set command just that the value is printed once on the serial in return.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests