I’m trying to send data from a NodeMCU to an Arduino nano.
If I try to send data with one second delay - all working fine.
But if I try to send without delay or with a delay less than one second, then arduino sees data but nothing not does.
Arduino nano sketch:
#include <Servo.h>
Servo servo1;
int servo = 6;
int engine = 5;
void setup() {
Serial.begin(9600);
analogWrite(servo, 67);
servo1.attach(8);
}
void loop() {
if (Serial.available()) {
String model = Serial.readStringUntil(':');
i
f (model.equals("engine")){
String value = Serial.readStringUntil('c');
int power = value.toInt();
analogWrite(engine, power);
}
if (model.equals("servo")){
String value_servo = Serial.readStringUntil('c');
int power_servo = value_servo.toInt();
servo1.write(power_servo);
}
}
}
NodeMCU sketch:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "my_wifi_ssid";
const char* password = "my_wifi_password";
ESP8266WebServer server(80);
void get_vars(){
if (server.argName(0) == "engine"){
server.send(200, "text/plain", "Reading engine. Value: "+server.arg(0));
Serial.println("engine:"+server.arg(0)+"c");
}
if (server.argName(0) == "servo"){
server.send(200, "text/plain", "Reading engine. Value: "+server.arg(0));
Serial.println("servo:"+server.arg(0)+"c");
}
}
void setup(void){
main_stuff();
}
void loop(void){
server.handleClient();
}
void main_stuff(){
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.onNotFound(get_vars);
server.begin();
Serial.println("HTTP server started");
}
nothing not does
is a double negative ... it meanssomething does
.... it is unclear what you mean by that statement