Got two Wemos MIni's to talk to each other on desk.

 After trying a couple of programs that didn't work, I found these two: one sender and one receiver.

from  github 

https://github.com/bnbe-club/esp-now-examples-diy-62/blob/master/controller/controller.ino

Here's one of the pastes: https://pastebin.com/xJCJuc6Q


LHS, RHS is Wemos MIni 1, the sender, and Wemos Min1 2, the receiver. Worked well off the desk.

Next steps are to examine the code and find battery power so that range tests can be done. 

Here's the associated YouTube.

Here's code for Sender1:

/****************************************************************************************************************************************************

 /****************************************************************************************************************************************************

 *  TITLE: ESP-NOW Getting Started Examples

 *

 *  By Frenoy Osburn

 *  YouTube Video: https://youtu.be/_cNAsTB5JpM

 ****************************************************************************************************************************************************/


 /********************************************************************************************************************

  * Please make sure that you install the board support package for the ESP8266 boards.

  * You will need to add the following URL to your Arduino preferences.

  * Boards Manager URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json

 ********************************************************************************************************************/

 

 /********************************************************************************************************************

 *  Board Settings:

 *  Board: "WeMos D1 R1 or Mini"

 *  Upload Speed: "921600"

 *  CPU Frequency: "80MHz"

 *  Flash Size: "4MB (FS:@MB OTA:~1019KB)"

 *  Debug Port: "Disabled"

 *  Debug Level: "None"

 *  VTables: "Flash"

 *  IwIP Variant: "v2 Lower Memory"

 *  Exception: "Legacy (new can return nullptr)"

 *  Erase Flash: "Only Sketch"

 *  SSL Support: "All SSL ciphers (most compatible)"

 *  COM Port: Depends *On Your System*

 *********************************************************************************************************************/

 #include<ESP8266WiFi.h>

#include<espnow.h>


#define MY_NAME         "CONTROLLER_NODE"

#define MY_ROLE         ESP_NOW_ROLE_CONTROLLER         // set the role of this device: CONTROLLER, SLAVE, COMBO

#define RECEIVER_ROLE   ESP_NOW_ROLE_SLAVE              // set the role of the receiver

#define WIFI_CHANNEL    1


//uint8_t receiverAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};   // please update this with the MAC address of the receiver

uint8_t receiverAddress[] = {0x98, 0xF4, 0xAB, 0xBF, 0xEC, 0xCC};   // Mac adress of Wemos Mini 2


struct __attribute__((packed)) dataPacket {

  int sensor1;

  int sensor2;

  float sensor3;

};


void transmissionComplete(uint8_t *receiver_mac, uint8_t transmissionStatus) {

  if(transmissionStatus == 0) {

    Serial.println("Data sent successfully");

  } else {

    Serial.print("Error code: ");

    Serial.println(transmissionStatus);

  }

}


void setup() {

  Serial.begin(115200);     // initialize serial port

  

  Serial.println();

  Serial.println();

  Serial.println();

  Serial.print("Initializing...");

  Serial.println(MY_NAME);

  Serial.print("My MAC address is: ");

  Serial.println(WiFi.macAddress());


  WiFi.mode(WIFI_STA);

  WiFi.disconnect();        // we do not want to connect to a WiFi network


  if(esp_now_init() != 0) {

    Serial.println("ESP-NOW initialization failed");

    return;

  }


  esp_now_set_self_role(MY_ROLE);   

  esp_now_register_send_cb(transmissionComplete);   // this function will get called once all data is sent

  esp_now_add_peer(receiverAddress, RECEIVER_ROLE, WIFI_CHANNEL, NULL, 0);


  Serial.println("Initialized.");

}


void loop() {

  dataPacket packet;

  

  packet.sensor1 = 123;

  packet.sensor2 = 456;

  packet.sensor3 = 3.14;


  esp_now_send(receiverAddress, (uint8_t *) &packet, sizeof(packet));


  delay(3000);

}


And receiver------------------------------------------------------------------------------------------------------


/****************************************************************************************************************************************************

 *  TITLE: ESP-NOW Getting Started Examples

 *

 *  By Frenoy Osburn

 *  YouTube Video: https://youtu.be/_cNAsTB5JpM

 ****************************************************************************************************************************************************/


 /********************************************************************************************************************

  * Please make sure that you install the board support package for the ESP8266 boards.

  * You will need to add the following URL to your Arduino preferences.

  * Boards Manager URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json

 ********************************************************************************************************************/

 

 /********************************************************************************************************************

 *  Board Settings:

 *  Board: "WeMos D1 R1 or Mini"

 *  Upload Speed: "921600"

 *  CPU Frequency: "80MHz"

 *  Flash Size: "4MB (FS:@MB OTA:~1019KB)"

 *  Debug Port: "Disabled"

 *  Debug Level: "None"

 *  VTables: "Flash"

 *  IwIP Variant: "v2 Lower Memory"

 *  Exception: "Legacy (new can return nullptr)"

 *  Erase Flash: "Only Sketch"

 *  SSL Support: "All SSL ciphers (most compatible)"

 *  COM Port: Depends *On Your System*

 *********************************************************************************************************************/

 #include<ESP8266WiFi.h>

#include<espnow.h>


#define MY_NAME   "SLAVE_NODE"


struct __attribute__((packed)) dataPacket {

  int sensor1;

  int sensor2;

  float sensor3;

};


void dataReceived(uint8_t *senderMac, uint8_t *data, uint8_t dataLength) {

  char macStr[18];

  dataPacket packet;  


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


  Serial.println();

  Serial.print("Received data from: ");

  Serial.println(macStr);

  

  memcpy(&packet, data, sizeof(packet));

  

  Serial.print("sensor1: ");

  Serial.println(packet.sensor1);

  Serial.print("sensor2: ");

  Serial.println(packet.sensor2);

  Serial.print("sensor3: ");

  Serial.println(packet.sensor3);

}

 

void setup() {

    

  Serial.begin(115200);     // initialize serial port


  Serial.println();

  Serial.println();

  Serial.println();

  Serial.print("Initializing...");

  Serial.println(MY_NAME);

  Serial.print("My MAC address is: ");

  Serial.println(WiFi.macAddress());


  WiFi.mode(WIFI_STA);

  WiFi.disconnect();        // we do not want to connect to a WiFi network


  if(esp_now_init() != 0) {

    Serial.println("ESP-NOW initialization failed");

    return;

  }


  esp_now_register_recv_cb(dataReceived);   // this function will get called once all data is sent


  Serial.println("Initialized.");

}


void loop() {


}

----------------------------------------------------------


Wemos Mini Master--> Slave working



Comments

Popular posts from this blog

Spud sensor update 3 August 2022

Real time LDR readings sent to receiver Wemos Mini