Hi guys! I just find this forum and i'm trying to make a project but i'm stuck
I have 2 ESP8266 one is the client and one is the server. Both are connected to the home wifi.
For the client i have connected 4 button (all to 3v and D2-3-4-5).
For the server i have a buzzer and a MAX7219 where i want to display the message.
The project will work like this:
If i press the first button, the client will send a message to the server and the server will buzz and put a message on the display.
But for now... the connection works but if i press the button nothing appears...
I'll post my code, if you can help me... for now it's connected only 1 button.
Client UPDATED CODE
#include <SPI.h>
#include <ESP8266WiFi.h>
#define ACTIVATED LOW
const int ButtonBianco = D2;
const int ButtonVerde = D3;
const int ButtonGiallo = D4;
const int ButtonRosso = D5;
int StatoBianco = 0;
int StatoVerde = 0;
int StatoGiallo = 0;
int StatoRosso = 0;
char ssid[] = "Alex"; // SSID of your home WiFi
char pass[] = "Lori1234."; // password of your home WiFi
unsigned long askTimer = 0;
IPAddress server(192,168,0,80); // the fix IP address of the server
WiFiClient client;
void setup() {
Serial.begin(115200); // only for debug
pinMode (ButtonBianco, INPUT_PULLUP);
pinMode (ButtonVerde, INPUT_PULLUP);
pinMode (ButtonGiallo, INPUT_PULLUP);
pinMode (ButtonRosso, INPUT_PULLUP);
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
//Serial.print(".");
delay(500);
}
//pinMode(ledPin, OUTPUT);
}
void loop () {
client.connect(server, 80); // Connection to the server
StatoBianco = digitalRead(ButtonBianco);
StatoVerde = digitalRead(ButtonVerde);
StatoGiallo = digitalRead(ButtonGiallo);
StatoRosso = digitalRead(ButtonRosso);
if (StatoBianco == ACTIVATED) {
client.println("bianco\r");
} else if (StatoVerde == ACTIVATED) {
client.println("verde\r");
} else if (StatoGiallo == ACTIVATED) {
client.println("giallo\r");
} else if (StatoRosso == ACTIVATED) {
client.println("rosso\r");
}
//String answer = client.readStringUntil('\r'); // receives the answer from the sever
client.flush();
delay(2000); // client will trigger the communication after two seconds
}
And the server: UPDATED CODE
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN D4
#define CLK_PIN D5 // or SCK
#define DATA_PIN D7 // or MOSI
#define BIZZER_PIN D2
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
char ssid[] = "Alex"; // SSID of your home WiFi
char pass[] = "Lori1234."; // password of your home WiFi
WiFiServer server(80);
IPAddress ip(192, 168, 0, 80); // IP address of the server
IPAddress gateway(192,168,0,1); // gateway of your network
IPAddress subnet(255,255,255,0); // subnet mask of your network
void setup() {
Serial.begin(115200); // only for debug
pinMode(BIZZER_PIN, OUTPUT);
myDisplay.begin();
myDisplay.setIntensity(15);
myDisplay.displayClear(0);
WiFi.config(ip, gateway, subnet); // forces to use the fix IP
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
//Serial.print(".");
delay(500);
}
server.begin(); // starts the server
/* Serial.println("Connected to wifi");
Serial.print("Status: "); Serial.println(WiFi.status()); // some parameters from the network
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());
Serial.print("Networks: "); Serial.println(WiFi.scanNetworks());*/
}
int i = 0;
void funzbianco() {
i = 0;
myDisplay.displayScroll("BIANCO", PA_CENTER, PA_SCROLL_LEFT, 50);
while(i < 3){
digitalWrite(BIZZER_PIN, HIGH);
delay(1000);
digitalWrite(BIZZER_PIN, LOW);
delay(1000);
i++;
}
}
void loop () {
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
Serial.println("Client connected");
String request = client.readStringUntil('\r'); // receives the message from the client
if (myDisplay.displayAnimate()) {
myDisplay.displayReset(); }
Serial.print("From client: "); Serial.println(request);
if (request == "bianco"){
funzbianco();
}
client.flush();
}
client.stop(); // terminates the connection with the client
}
}
I don't understand what it's wrong.. can you please help me?
Thanks!