Hi
What I'm trying to do:
I use an Arduino Uno with a Grove UART Wifi V2 connected to the Serial Port of the Arduino to send a HTTP-POST request to a REST-Endpoint.
What works:
I am able to init the Wifi-Board and to connect the board to an Access Point. I can see the connected board in my Access Point.
What does not work:
When i try to establish the connection (line "if (wificlient.connect(""), the connect-method returns false. The statusCode will be 0.
Does anyone know what is wrong? I couldn't find any error in my code, comparing it to all forum-posts and examples I could found.
Many thanks.
// test grove - uart wifi
// scan ap and display on Grove - OLED 0.96'
// Loovee @ 2015-7-28
#include "Arduino_SensorKit.h"
#include "WiFiEsp.h"
char ssid[] = "SECRET"; // your network SSID (name)
char pass[] = "SECRET"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 20000L; // delay between updates, in milliseconds
WiFiEspClient wificlient;
void setup()
{
Serial.begin(115600);
Oled.begin();
Oled.setFlipMode(true);
Oled.setFont(u8x8_font_chroma48medium8_r);
Oled.setCursor(0, 33);
Oled.clear(); // clear the screen and set start position to top left corner
Oled.println("Add WiFi-Module");
delay(5000);
WiFi.init(&Serial);
delay(5000);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Oled.print("Wifi shield not found");
// don't continue
while (true);
}
Oled.clear();
Oled.setCursor(0, 33);
Oled.print("Wifi shield ok");
delay(5000);
// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
Oled.clear();
Oled.setCursor(0, 33);
Oled.println("Attempting to connect to WPA SSID: ");
Oled.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Oled.clear();
Oled.setCursor(3, 33);
Oled.println("Connected!!");
delay(5000);
Oled.clear();
int statusCode = -5;
if (wificlient.connect("europe-central2-m-242-project.cloudfunctions.net", 80)) {
Oled.println("GET...");
String content = "Hey, just testing a post request.";
wificlient.println("POST https://europe-central2-m-242-project.cloudfunctions.net/datacollectorV1 HTTP/1.1");
wificlient.println("Host: https://europe-central2-m-242-project.cloudfunctions.net:80");
wificlient.println("Accept: */*");
wificlient.println("Content-Length: " + content.length());
wificlient.println("Content-Type: application/x-www-form-urlencoded");
wificlient.println();
wificlient.println(content);
}
// read the status code and body of the response
statusCode = wificlient.status();
Oled.print("Status code: ");
Oled.println(statusCode);
delay(5000);
}
void loop()
{
}