I'm having a problem whereby I cant get client to connect when using URL. It works fine when I connect to a local server using IP address but when I change to remote server via URL it wont connect. I have ported from a program using mega with esp8266 which works fine with remote servers but that is a different library.
I have put a force dns into the mix because I thought that was the problem in WiFi.h but it made no difference.
any pointers or suggestions would be well appreciated.
#include <WiFi.h>
// ****************************************************
// network connection parameters
// ****************************************************
const char* ssid = "****"; // ver espmon3
const char* password = "****"; // ver espmon3
//const char* host = "192.168.11.59"; // ver espmon3
const int httpPort = 80; // ver espmon3
const char* host = "www/vitalstates.org"; // ver espmon7
// ********************************************
// from the mast transmitter
// ********************************************
short station_id; // station identifier
int humidity; // processed humidity value
int direct; // wind direction degrees of 16th segment
int interval;
float wind; // processed wind speed
WiFiClient client;
// *************************************************************************************
void init_wifi()
{
WiFi.begin(ssid, password); // ver espmon2
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
// force the dns
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(8,8,8,8));
}
// ************************************************************************************
void setup()
{
Serial.begin(19200);
Serial.println();
station_id = 1234;
interval = 2;
direct = 5;
wind = 6.5;
init_wifi();
}
//
// **********************************************************************************
//
void loop()
{
upload_packet();
delay(5000);
}
void upload_packet()
{
String msg;
if (WiFi.status() != WL_CONNECTED) {init_wifi();}
if (!client.connect(host, httpPort))
{
Serial.println("upload connection failed");
return;
}
msg = "/weather/weatherupload.php?";
msg = msg+"id=";
msg = msg+station_id;
msg = msg+"&gap=";
msg = msg+interval;
msg = msg+"&direct=";
msg = msg+direct;
msg = msg+"&wind=";
msg = msg+wind;
client.print(String("GET ") + msg + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n"); // send message
Serial.println("upload ok");
}