Hello everyone!Decided to use Arduino as slave, and ESP-01 as master.GunnerTechTools thanks for the idea!The Board for some reason does not want to listen to the master.I use the widget “button” to switch the diode on the Arduino Board,but the diode only jerks nervously and everything,both on the Arduino Board and on the esp-01.Uploaded code
for master:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EasyTransfer.h>
//create object
EasyTransfer ET;
struct SEND_DATA_STRUCTURE {
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int16_t LED13;
};
//give a name to the group of data
SEND_DATA_STRUCTURE ETdata;
char auth[] = "BuR";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI";
char pass[] = "";
char server[] = "blynk-cloud.com";
int port = 8080;
void setup() {
Serial.begin(9600);
ET.begin(details(ETdata), &Serial);
Blynk.config(auth, server, port);
Blynk.connect();
}
BLYNK_WRITE(V3){
ETdata.LED13 = param.asInt();
digitalWrite(1, !param.asInt());
ET.sendData();
}
void loop() {
Blynk.run();
}
And code for slave:
#include <EasyTransfer.h>
//create object
EasyTransfer ET;
struct RECEIVE_DATA_STRUCTURE {
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int16_t LED13;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE ETdata;
void setup() {
Serial.begin(9600);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(ETdata), &Serial);
pinMode(13, OUTPUT);
}
void loop() {
//check and see if a data packet has come in.
ET.receiveData();
if (ETdata.LED13 == 1) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
delay(2000);
}
}
Diode on Arduino and on the esp-01 quick flashes and goes out it’s connected to Blynk.What can be such behavior?
GunnerTechTools respect,showed a very necessary way of interaction between the two boards.Another question:got to do a few slaves,who passed one to master the readings on the sensors?For example,many-Arduino-one Wemos d1 mini pro?
Please edit your post and add triple backticks at the beginning and end of your code, so that it displays correctly.
Triple backticks look like this:
```
Not quite, you only had three sets of backticks, not four, but I fixed it for you.
It’s important to get the code formatting right, because if people copy and paste it into the Arduino IDE some characters get corrupted, so it’s impossible for people to help you with debugging.
Help others to help you, by getting the code formatting right in future.
The way you have this written, it is processing this function twice for each Button Widget use… once for press and once for release… thus effectively flashing the LED state ON/OFF based on the Button state, not toggling the LED state at each button press.
A more precise way of processing on button press only is like this…
BLYNK_WRITE(vPin){
if (param.asInt() == 1) {
// do something when button pressed
} else {
// do something, or nothing, on button release
}
However, then you would need additional methods to determine and process the current state and required action of the LED.
I suspect that for your desired action, simply setting the Button Widget to Switch will accomplish the needed task.
PS, the delay() in the slave loop is unnecessary, and may actually cause issues “hearing” multiple actions from the master if they happen during that delay time.
Here tried to do something a little different,as you suggest,but still led at the push of a button quickly turn on and off.
code master:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EasyTransfer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
//create object
EasyTransfer ET;
struct SEND_DATA_STRUCTURE {
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int16_t LED13;
};
//give a name to the group of data
SEND_DATA_STRUCTURE ETdata;
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI";
char pass[] = "";
char server[] = "blynk-cloud.com";
int port = 8080;
BlynkTimer timer;
WidgetRTC rtc;
// Digital clock display of the time
void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V1, currentTime);
// Send date to the App
Blynk.virtualWrite(V2, currentDate);
}
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
}
void setup() {
Serial.begin(9600);
ET.begin(details(ETdata), &Serial);
Blynk.config(auth, server, port);
Blynk.connect();
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
// Display digital clock every 10 seconds
timer.setInterval(10000L, clockDisplay);
}
BLYNK_WRITE(V3) {
if (param.asInt() == 1) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
ET.sendData();
}
void loop() {
Blynk.run();
timer.run();
}
slave code:
#include <EasyTransfer.h>
//create object
EasyTransfer ET;
struct RECEIVE_DATA_STRUCTURE {
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int16_t LED13;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE ETdata;
void setup() {
Serial.begin(9600);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(ETdata), &Serial);
pinMode(13, OUTPUT);
}
void loop() {
if (ET.receiveData()) {
if (ETdata.LED13 == 1) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
delay(2000);
}
}
}
Can you tell me where I’m wrong?Tried in variable V3 assign all tried,but or error,or as it is now - button is pressed,and diodik flickers.I want to understand how to then send other variables to see them in the application.Please help a little:sweat_smile:
A bit code merged,so that,when the end and beginning of put triple quotes,then why it does not format code:скалить зубы:
In your Master sketch you’ve created a variable called LED13, but you never assign any value to it in your master code. How can this master sketch know what data to send to the Slave?
Dear Pete, is this the right thing to do?But so, too, the errors are shot - too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’.
What am I wrong about?
In General, I removed the delay, as you advised, but the code still does not work,so I would like.In the application switched from " push “to” switch " and also nothing.What else could be the problem?
#include <SimpleTimer.h>
#include <EasyTransfer.h>
EasyTransfer ET;
SimpleTimer timer;
struct RECEIVE_DATA_STRUCTURE {
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int16_t LED13;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE ETdata;
void setup() {
Serial.begin(9600);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(ETdata), &Serial);
pinMode(13, OUTPUT);
}
void loop() {
if (ET.receiveData())
timer.setInterval (2000, [] () {
if (ETdata.LED13 == 1)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
});
}
This makes very little difference to the issue that @Gunner was referring to.
In Push mode the widget will send a 1 when pressed and a 0 when released. unless you keep your finger on the button for some time, they’ll be sent in very quick succession.
in Switch mode a 1 is send when you press the button to turn it off, and a 0 is sent when you press it again to turn it off.
I think you probably need to be monitoring that data that is sent over the serial interface from the Master to be able to understand what’s happening.
I think you also need to elaborate on the “it doesn’t work the way I want it to” type of statements.
Hello, dear Pete.If I fill almost such code as on the master, then it works as I want, i.e.-when pressing the button the led lights up, and when pressing once again goes out.What I would like to get here.And here he only blinks and all and not is understandable the reason all this.I wanted to understand, because in the future it would be necessary to transfer the control of relays and various sensors.The relay itself would have to be switched on,like an led, only in time.
@Technogrover, I’m afraid that none of what you said makes any sense to me.
Maybe you should write, in as much detail as possible and in your own language (Russian?) what it is that you’re trying to achieve and let us translate it into English.
Уважаемый Пит,английский обещаю выучить хорошо,как только будет у меня свободное время,сейчас свободное время трачу на микроконтроллеры и Blynk:скалить зубы:
Моя задача:1)Попытаться сделать технотент для выращивания рассады с помощью Blynk.
2)В самом тенте должно быть реализовано управление розетками и датчиками.Здесь на помощью приходит Eventor для розеток.Датчики должны все лишь показывать температуру в тенте,возможно co2 и влажность в горшках.
3)Сидя тут на форуме,увидел,как GunnerTechTools использовал esp как мастера и мне захотелось попробовать повторить эксперимент.Использование esp как мастера решает многие проблемы,но вот саму логику управления с помощью easytransfer мне не понять.Я экономист по образованию,а это просто типо хобби:sweat_smile:
Надеюсь,что так немного вам станет более ясно,что я хочу:ухмыляющийся:
Lots of interesting background information, but nothing that tells me exactly what problem it is that you are experiencing and how we can help you overcome it.
We need technical details about EXACTLY what is and isn’t working for you, and what data you are seeing sent over the serial interface from the master and under what circumstances you see this data.
Personally, I think that you are making your life much more difficult choosing this hardware setup. Life would probably be much easier if you used a NodeMCU.
Вы знаете,все получилочь:ухмыляющийся: Теперь диод мигает с помощью кнопки в приложении.Причем,я убрал все задержки,какие были,но это,наверное,не совсем правильно?После if(ET.receiveData()),когда будут датчики и реле нужна всегда задержка?
NodeMCU я рассматривал в самом начале своего пути,но если бы на нем было больше gpio,то его бы,конечно,и взял,но хотелось,чтобы всем тентом управлял один микроконтроллер:upside_down_face:
Последовательный монитор у меня всегда пустой:zipper_mouth_face: