IOT-MCU / ESP-12S-A9-A9G-GPRS-Node-v1.0

63 stars 27 forks source link

Unable to connect to local server using wificlient #17

Closed ayazurrehman786 closed 3 years ago

ayazurrehman786 commented 3 years ago

Hello, I m unable to connect to local server while it can connect to web server. Can anyone help.

include

include

include

include

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Setting MAC Address

char server[] = "192.168.1.151/Project2/dht_new.php?humidity=30&temperature=96"; IPAddress ip(192,168,1,177);

char ssid[] = "dlink-1880"; // your SSID char pass[] = "Mohammad1"; // your SSID Password

// Initialize the client library WiFiClient client; float humidityData, temperatureData;

void setup() { Serial.begin(115200); WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {

delay(1000); Serial.println("Connecting...");

} Serial.println(); Serial.print("WIFI Local IP: "); Serial.print(WiFi.localIP());

if (WiFi.status() == WL_CONNECTED) { Serial.println(); Serial.println("Connected to wifi"); Serial.println("\nStarting connection..."); // if you get a connection, report back via serial:

} } //------------------------------------------------------------------------------

/ Infinite Loop / void loop(){ humidityData = 12.88; temperatureData = 98.4; Sending_To_phpmyadmindatabase(); delay(2000); // interval }

void Sending_To_phpmyadmindatabase() //CONNECTING WITH MYSQL { if (client.connect(server, 139)) { Serial.println("connected"); // Make a HTTP request: Serial.print("GET /Project2/dht_new.php?humidity="); client.print("GET /Project2/dht_new.php?humidity="); //YOUR URL client.print(humidityData); client.print("&temperature="); Serial.println("&temperature="); client.print(temperatureData); client.print(" "); //SPACE BEFORE HTTP/1.1 client.print("HTTP/1.1"); client.println(); client.println("Host: 192.168.1.151"); client.println("Connection: close"); client.println(); } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } }