🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    ESP-Now UIFlow to Arduino

    UIFlow
    3
    4
    8.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Xio1996X
      Xio1996
      last edited by Xio1996

      Dear All,

      I am trying to send a message using the EspNow blocks in UIFlow to an ESP32 running an Arduino program. The message is sent and received but I can't seem to get the data in the Arduino program it just returns '1' even though the length alters as I alter the data being sent. When I look at the Python code it is sending a string, so I think I'm asking how to convert a Python string into an Arduino string/character array. Sorry if this is a real newbie question.

      Blocky - Python code
      def buttonA_wasPressed():
      global iCount
      espnow.send(id=1, data=str('HELLO!'))
      pass
      btnA.wasPressed(buttonA_wasPressed)

      Arduino ESP-Now receive code
      void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
      {
      char macStr[18];
      char sData[data_len];

      snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
      mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
      Serial.print("Last Packet Recv from: "); Serial.println(macStr);
      Serial.print("Data Length: "); Serial.println(data_len);
      Serial.print("Last Packet Recv Data: "); Serial.println(*data);
      Serial.println("");
      }

      Arduino Output
      11:39:37.342 -> Last Packet Recv from: d8:a0:1d:55:4b:38
      11:39:37.342 -> Data Length: 16
      11:39:37.342 -> Last Packet Recv Data: 1
      11:39:37.342 ->

      1 Reply Last reply Reply Quote 0
      • L
        lukas
        last edited by

        Hey

        since you pass a pointer to the println-function and the cpu does not know what type of data is located at that position this behaviours seems normal.
        In the example in the link they create a structure for the transmitted data. In the callback they copy the recieved data in this structure and later you can print exactly what you want:
        https://randomnerdtutorials.com/esp-now-esp32-arduino-ide/

        1 Reply Last reply Reply Quote 1
        • Xio1996X
          Xio1996
          last edited by

          Hi Lukas,

          Thank you for the link. I will see if I can use their method. I did find a solution that works.

          I noticed that the received data starting at index 11 was getting ASCII codes so I modified the Arduino code to construct a String starting from that position. The ESP-Now OnDataRecv callback now looks like this (the string construction is in bold).

          void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
          {
          char macStr[18];

          String tData="";
          char Ascii[1];
          for(int i=10;i<data_len;i++)
          {
          tData+=(char)data[i];
          }

          snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
          mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

          Serial.print("Last Packet Recv from: "); Serial.println(macStr);
          Serial.print("Data Length: "); Serial.println(data_len);
          Serial.print("Last Packet Recv Data: '"); Serial.print(tData);
          Serial.println("'");
          }

          Arduino Output

          13:38:11.806 -> Last Packet Recv from: d8:a0:1d:55:4b:38
          13:38:11.806 -> Data Length: 22
          13:38:11.806 -> Last Packet Recv Data: 'Hello World!'

          F 1 Reply Last reply Reply Quote 1
          • F
            fbritop @Xio1996
            last edited by

            @xio1996 I was trying to do the same thing. I have some ESP01 relay controlers, which they work fine between them aand an ESP32 WROOM. I'm now trying to use a Core2 as a master, but I haven't been able to communicate with the ESP01.

            Do you have any example codes for Core5 in MicroPython?

            Thanks in advance
            FBP

            1 Reply Last reply Reply Quote 0
            • First post
              Last post