Existe algum comando para enviar uma determinada função através da rede
Ou seja enviar para um determinado ip + funcão (192.168.0.99/mensagem1)
Tags:
Boa noite,
Sugiro que seja mais explicito veja este link http://labdegaragem.com/forum/topics/sugest-o-de-como-postar
Meu canal: https://www.youtube.com/channel/UCLZ2cga6-yqz5jtI-XvE7PA?view_as=su...
Abs.
CK
#include "SSD1306.h"
SSD1306 display(0x3c, 5, 4);
#include <WiFi.h>
byte mac[6];
const char* wifi_name = "Travanca";
const char* wifi_pass = "samuelisabel2016";
WiFiServer server(80);
// Variable to store the HTTP request
String header;
String inString = String(35);
void setup() {
Serial.begin(115200);
IPAddress ip(192,168,0,187);
IPAddress gateway(192,168,0,254);
IPAddress subnet(255,255,255,0);
WiFi.config(ip, gateway, subnet);// Ip manual
WiFi.begin(wifi_name, wifi_pass); //Connecting to wifi network
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
server.begin();
Serial.println("Conected");
Serial.println(WiFi.localIP());
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[0],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.println(mac[5],HEX);
display.init();
display.setI2cAutoInit(true);
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
//display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 0, "Sex, 2018-08-30");
display.drawString(85, 0, "13:42:02");
display.drawString(0, 50, "Portão 1");
display.drawString(0, 15, "192.168.0.187 - 80");
display.display();
}
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
if (header.indexOf("GET /enviasms1") >= 0) {
//objectivo enviar comando para um ip ex 192.168.0.190/lux2
Serial.println("Mensagem 1 enviada");
}
else {
Serial.println("Sem função reconhecida");
}
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
client.println("<body><h1>ESP32 Web Server</h1>");
client.println("<a href=\"/enviasms1\"\"><button>Ligar </button></a>");
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
O jeito mais simples é por socket.
Por socket vc manda uma mensagem para um IP.
O exemplo tipico é um chat, onde não se usa HTML, nada. Vc faz do seu jeito. Um MSN da vida.
Só que o codigo sumiu... pelo menos aqui.
https://www.arduino.cc/en/Tutorial/ChatClient
Só esses estão disponiveis:
https://www.arduino.cc/en/Tutorial/AdvancedChatServer
ja estive a ler
Encontrei o a comunicação esp-now parece-me rápida
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por