I m trying to connect Esp 8266 breakout board with EM 18 RFID module and send RFid tag data to Local host server using a php code I need to use static ip , I tried connecting using internet settings (web hosting) its working good but in intranet (using static ip ) Im getting errors pls help me to resolve my issue
#include <Wire.h>
#include <ESP8266WiFi.h>
const char* ssid = "";
const char* pwd = "";
const char* base_host = "192.168.1.102";
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pwd);
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);
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
REQUIRE(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);
String events;
auto handler1 = WiFi.onStationModeConnected([&](const WiFiEventStationModeConnected& evt){
events += "connected,";
});
auto handler2 = WiFi.onStationModeDisconnected([&](const WiFiEventStationModeDisconnected& evt){
if (events.length()) {
events += "disconnected,";
}
});
auto handler3 = WiFi.onStationModeGotIP([&](const WiFiEventStationModeGotIP& evt){
events += "got_ip,";
});
}
char product_tag[12];
void loop() {
delay(50);
if(Serial.available() >= 1)
{
if (server.hasClient()){
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (!serverClients[i] || !serverClients[i].connected()){
if(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available();
Serial1.print("New client: "); Serial1.print(i);
continue;
}
}
char i = 0;
while(i > 2)
{
Serial.read();
Serial.read();
char data = Serial.read();
product_tag[i++] = data;
}
while(Serial.read() != -1); // Clear data in queue
product_tag[i] = '\0';
Serial.print("connecting to ");
Serial.println(base_host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(base_host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/app/rfid_iot/addRFIDTag.php";
url += "?hanger=1&line=1&table=1&product_tag=";
url += product_tag;
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"base_host: " + base_host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 22000) {
client.stop();
return;
}
}
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
while(Serial.read() != -1); // Clear data in queue
}
}