我正在尝试将 Esp 8266 分线板与 EM 18 RFID 模块连接起来,并使用我需要使用静态 ip 的 php 代码将 RFID 标签数据发送到本地主机服务器,我尝试使用 Internet 设置(网络托管)进行连接,它工作正常但在 Intranet 中(使用静态 ip)我收到错误请帮助我解决我的问题
#include
#include
const char* ssid = "";
const char* pwd = "";
const char* base_host = "192.168.1.102";
void setup() {
Serial.begin(115200);
延迟(10);
序列号.println();
序列号.println();
Serial.print("连接到");
序列号.println(ssid);
无线上网。
while (WiFi.status() != WL_CONNECTED) {
sEventsReceived[WIFI_EVENT_STAMODE_CONNECTED] = 0;
sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] = 0;
sEventsReceived[WIFI_EVENT_STAMODE_GOT_IP] = 0;
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_CONNECTED);
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_DISCONNECTED);
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_GOT_IP);
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY);
延迟(500);
序列号.print(".");
}
Serial.println("");
Serial.println("WiFi 已连接");
Serial.println("IP地址:");
Serial.println(WiFi.localIP());
要求(sEventsReceived [WIFI_EVENT_STAMODE_CONNECTED] == 2);
REQUIRE(sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] >= 2 && sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] % 2 == 0);
REQUIRE(sEventsReceived[WIFI_EVENT_STAMODE_GOT_IP] == 2);
字符串事件;
auto handler1 = WiFi.onSta
tionModeConnected([&](const WiFiEventStationModeConnected& evt){
events += "connected,";
});
auto handler2 = WiFi.onStationModeDisconnected([&](const WiFiEventStationModeDisconnected& evt){
if (events.length()) {
events += "disconnected,";
}
});
auto handler3 = WiFi.onStationModeGotIP([&](const WiFiEventStationModeGotIP&
});
}
char product_tag[12];
void loop() {
延迟(50);
if(Serial.available() >= 1)
{
if (server.hasClient()){
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (!serverClients[i] || !serverClients[i].connected ()){
如果(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available();
Serial1.print("新客户:"); Serial1.print(i);
继续;
}
}
炭我= 0;
while(i > 2)
{
Serial.read();
串口.read();
字符数据 = Serial.read();
产品标签[i++] = 数据;
}
while(Serial.read() != -1); // 清除队列中的数据
product_tag[i] = '\0';
Serial.print("连接到");
Serial.println(base_host);
WiFiClient客户端;
const int httpPort = 80;
if (!client.connect(base_host, httpPort)) {
Serial.println("连接失败");
返回;
}
字符串 url = "/app/rfid_iot/addRFIDTag.php";
url += "?hanger=1&line=1&table=1&product_tag=";
url += 产品标签;
Serial.print("请求地址:");
Serial.println(url);
client.print(String("GET") + url + " HTTP/1.1\r\n"
"连接:关闭\r\n\r\n");
无符号长超时=毫秒();
while (client.available() == 0) {
if (millis() - timeout > 22000) {
client.stop();
返回;
}
}
while(client.available()){
String line = client.readStringUntil('\r');
串行打印(行);
}
Serial.println();
Serial.println("关闭连接");
while(Serial.read() != -1); // 清除队列中的数据
}
}