Hi all,
My project is to log data on a google spreadsheet. I saw several exemple to do that with Arduino, so I was confident when I bought a UNO wifi rev2, but...
The code is able to :
- connect to wifi : ok
- connect to server : ok
- read get response : ok (HTTP 1.1 200 ok)
So everything seems to be ok but the parameter of the request (?keyid=value) is not passed.
If using the same string request in a browser, the parameter is correctly sent.
I need your help to understand what is wrong with my code :
/*
Web client
This sketch connects to a website (http://www.google.com)
using the WiFi module.
This example is written for a network using WPA encryption. For
WEP or WPA, change the Wifi.begin() call accordingly.
This example is written for a network using WPA encryption. For
WEP or WPA, change the Wifi.begin() call accordingly.
Circuit:
Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe
*/
#include <SPI.h>
#include <WiFiNINA.h>
//#include <Arduino_JSON.h>
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "xxx"; // your network SSID (name)
char pass[] = "xxx"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
const char server[] = "script.google.com"; // name address for Google (using DNS)
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiSSLClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWiFiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connectSSL(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /macros/s/xxxxx/exec?message=fromarduino HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Access-Control-Allow-Origin: *");
client.println("Connection: close");
client.println();
}
Serial.print("status: ");
Serial.println(client.status());
Serial.println(client.available());
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true)
;
}
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
I notice that all the similar project to log data on Gsheet was done with other boards, so other library (HTTPClient.h or HTTPSRedirect.h).
So is the problem is link to WIFININA library?
I'm stuck, I need your help.