hello, i bought a relay board based on the esp12f module and i was able to program it through ttl and communicate in serial at some point in the loop but if i want to send a serial message in the setup i get only weird characters no matter what baudrate i use. i am trying to communicate through esP now but so far it doesn't work only between 2 node mcu 8266 board but not betwen this relay board and nodemcu . i saw that the 12f has a bit longer antenna what can be the problem ? https://templates.blakadder.com/assets/ESP12F_Relay_X4.pdf
Post a wiring diagram of your setup. Describe exactly what your trying to achieve and what exact result you get. Post the code you used for that.
this board is the receiver board powered from 5v from pc usb and i have a node mcu esp8266 board conected thorugh cable to pc. i am able to comunicate betwen 2 mcu but not betwen mcu and this relay board even that i think i got the right mac address, i am wondering if they are the same type and can comunicate since the board has the last copper trace on the antenna a bit longer
/*
TRANSMITTER
*/
//libraries
#include <ESP8266WiFi.h>
#include <espnow.h>
//esp8266 transmitter object
uint8_t broadcastAddressA[] = {0xE8, 0x68, 0xE7, 0xD1, 0xEA, 0xF3}; //adress for SLAVE receiver board1 e8:68:e7:d1:ea:f3
uint8_t broadcastAddressB[] = {0x32, 0xAE, 0xA4, 0x07, 0x0D, 0x66}; //adress for SLAVE receiver board2
uint8_t broadcastAddressC[] = {0xCC, 0x50, 0xE3, 0x3C, 0xA8, 0x4B}; //adress for SLAVE receiver board3
uint8_t broadcastAddressD[] = {0xCC, 0x50, 0xE3, 0x3C, 0xA8, 0x4B}; //adress for SLAVE receiver board4
//esp data to send
typedef struct struct_message {
char letter;
} struct_message;
struct_message espData;
//esp send data function
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
if (sendStatus == 0) {
Serial.println("Delivery success");
}
else {
Serial.println("Delivery fail");
}
}
char receiver_board_indicative = 'X';
void setup() {
Serial.begin(115200);
//data to send
espData.letter = 'O';
//Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
WiFi.disconnect();
// Init ESP-NOW
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
Serial.flush();
ESP.restart();
return;
} else {
Serial.println();
Serial.println("ESP-NOW initialized successfully");
Serial.print("MAC-ADDRESS ");
Serial.println(WiFi.macAddress());
}
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_register_send_cb(OnDataSent);
esp_now_add_peer(broadcastAddressA, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
esp_now_add_peer(broadcastAddressB, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
esp_now_add_peer(broadcastAddressC, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
esp_now_add_peer(broadcastAddressD, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
ESP.wdtDisable();
}
void loop() {
//feed watchdog
ESP.wdtFeed();
if (Serial.available() == 2) {
espData.letter = Serial.read();
receiver_board_indicative = Serial.read();
Serial.println(espData.letter);
Serial.println(receiver_board_indicative);
}
if (espData.letter != 'O') {
switch (receiver_board_indicative) {
case 'A':
esp_now_send(broadcastAddressA, (uint8_t *) &espData, sizeof(espData));
break;
case 'B':
esp_now_send(broadcastAddressB, (uint8_t *) &espData, sizeof(espData));
break;
case 'C':
esp_now_send(broadcastAddressC, (uint8_t *) &espData, sizeof(espData));
break;
case 'D':
esp_now_send(broadcastAddressD, (uint8_t *) &espData, sizeof(espData));
break;
}
receiver_board_indicative = 'X';
espData.letter = 'O';
}
}
/*
RECEIVER
*/
//libraries
#include <ESP8266WiFi.h>
#include <espnow.h>
//board id
#define BOARD_INDICATIVE A
//esp data to receive
typedef struct struct_message {
char letter;
} struct_message;
struct_message espData;
boolean ReceivedData = false;
//relays variables
//pins; D1-GPIO5,D2-GPIO4,D6-GPIO12,D7-GPIO13
const int relayA = 13; // GPIO 13 = D7
const int relayB = 12; // GPIO 12 = D6
const int relayC = 14; // GPIO 14 = D5
const int relayD = 16; // GPIO 16 = D0
boolean RelayStateA = HIGH;
boolean RelayStateB = HIGH;
boolean RelayStateC = HIGH;
boolean RelayStateD = HIGH;
//function for receiving
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) {
memcpy(&espData, incomingData, sizeof(espData));
ReceivedData = true;
// Serial.printf("Board ID %d \n", espData.id);
// Serial.printf("letter value: %d \n", espData.letter);
// Serial.println();
}
void delayFct () {
ESP.wdtFeed();
delay(500);
}
void setup() {
// Initialize Serial Monitor
//Serial.begin(115200);
//relays initialization
digitalWrite(relayA, HIGH);
digitalWrite(relayB, HIGH);
digitalWrite(relayC, HIGH);
digitalWrite(relayD, HIGH);
pinMode(relayA, OUTPUT); // OUTPUT 5V
pinMode(relayB, OUTPUT);
pinMode(relayC, OUTPUT);
pinMode(relayD, OUTPUT);
espData.letter = 'O';
//Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
WiFi.disconnect();
// Init ESP-NOW
if (esp_now_init() != 0) {
// Serial.println("Error initializing ESP-NOW");
// Serial.flush();
ESP.restart();
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);
ESP.wdtDisable();
}
void loop() {
//feed watchdog
ESP.wdtFeed();
//if we got new data, activate the relays
if (ReceivedData == true) {
switch (espData.letter) {
case 'A': //ON
if (RelayStateA == LOW) {
digitalWrite(relayA, HIGH);
RelayStateA = HIGH;
}
delayFct();
break;
case 'B': //ON
if (RelayStateB == LOW) {
digitalWrite(relayB, HIGH);
RelayStateB = HIGH;
}
delayFct();
break;
case 'C': //ON
if (RelayStateC == LOW) {
digitalWrite(relayC, HIGH);
RelayStateC = HIGH;
}
delayFct();
break;
case 'D': //ON
if (RelayStateD == LOW) {
digitalWrite(relayD, HIGH);
RelayStateD = HIGH;
}
delayFct();
break;
case 'E': //OFF
if (RelayStateA == HIGH) {
digitalWrite(relayA, LOW);
RelayStateA = LOW;
}
delayFct();
break;
case 'F': //OFF
if (RelayStateB == HIGH) {
digitalWrite(relayB, LOW);
RelayStateB = LOW;
}
delayFct();
break;
case 'G': //OFF
if (RelayStateC == HIGH) {
digitalWrite(relayC, LOW);
RelayStateC = LOW;
}
delayFct();
break;
case 'H': //OFF
if (RelayStateD == HIGH) {
digitalWrite(relayD, LOW);
RelayStateD = LOW;
}
delayFct();
break;
case 'N': // OPRESTE TOATE RELEELE
digitalWrite(relayA, LOW);
RelayStateA = LOW;
digitalWrite(relayB, LOW);
RelayStateB = LOW;
digitalWrite(relayC, LOW);
RelayStateC = LOW;
digitalWrite(relayD, LOW);
RelayStateD = LOW;
delayFct();
break;
case 'P': // PORNESTE TOATE RELEELE
digitalWrite(relayA, HIGH);
RelayStateA = HIGH;
digitalWrite(relayB, HIGH);
RelayStateB = HIGH;
digitalWrite(relayC, HIGH);
RelayStateC = HIGH;
digitalWrite(relayD, HIGH);
RelayStateD = HIGH;
delayFct();
break;
default:
espData.letter = 'O';
break;
}
ReceivedData = false;
}
}
The first sketch addresses 4 boards. Why? In your description only 2 boards are mentioned.
because i have 4 identical relays boards, it did work finaly for 2 of them but one still doesn't work only the uploaded scketch. i believe i messed the mac address when i tried to read it i uploaded the change mac address code, is there a method to reset it ?
To reset the MAC address? To my knowledge that isn't possible that's hard wired.
#include <ESP8266WiFi.h>
// Set your new MAC Address
uint8_t newMACAddress[] = {0x32, 0xAE, 0xA4, 0x07, 0x0D, 0x66};
void setup(){
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_STA);
Serial.print("[OLD] ESP8266 Board MAC Address: ");
Serial.println(WiFi.macAddress());
// For Soft Access Point (AP) Mode
//wifi_set_macaddr(SOFTAP_IF, &newMACAddress[0]);
// For Station Mode
wifi_set_macaddr(STATION_IF, &newMACAddress[0]);
Serial.print("[NEW] ESP8266 Board MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop(){
}
i did this
I solved, 2 boards work, i powered them from usb 5v wich was not enough and not powered by 12v or 230 on board transformer/ regulators it works. the third board is faulty but the code works only it doesn't want to receive data thorugh rf
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.