<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h«®=owser sent a request tha164 xxxx
t this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead use t«®=me to access this URL, p164xxxxx
lease.<br />
<blockquote>Hint: <a href="xxxx"><b>hxxxx</b></a></blockquot129hxxxx
e></p>
- Code: Select all
void printData(char* data, int len) {
//print the data returned by the server
//note that the data is not null-terminated, may be broken up into smaller packets, and includes the http header.
while (len-- > 0) {
Serial.print(*(data++));
}
}
//ip address
uint8 ip[] = {xxx,xx,xxx,xxx};
char hostname[] = "https://whatever";
uint8 ipaddr[] = {xxx,xx,xxx,xxx};
char uri[] = "/Sensor/";
char key[] = API_KEY;
const int port = 443;
//function to combine and allocate
char *combined(char result[], size_t result_sz, const char key[], const char uri[]) {
//test to see if there is sufficient space */
if (strlen(uri) + strlen(key) + 1 > result_sz) {
return NULL;
}
strcpy(result, uri);
strcat(result, key);
return result;
}
//a get request
char lon[1024];
char *newURI = combined (lon, sizeof lon, key, uri);
GETrequest getSession(ipaddr, port, hostname, newURI);
void setup() {
//initialize wiserver (we'll pass null for the page serving function since we don't need to serve web pages)
WiServer.init(NULL);
//enable serial output and ask wierver to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
//have the processData function called when data is returned by the server
getSession.setReturnFunc(printData);
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;
void loop(){
// Check if it's time to get an update
//if (millis() >= updateTime) {
getSession.submit();
// Get another update one min from now
// updateTime += 1000 * 20;
//}
// Run WiServer
WiServer.server_task();
delay(10);
}