I have a sketch which I'm using to connect to a Google Apps Script URL (desired URL: https://script.google.com/a/macros/edwardmarno.com/s/XXXXXX/exec?Weight=3450*) in order to pass a weight parameter to a Google Sheet. The sketch connects to my wifi fine but then it doesn't go to the URL correctly. Please could someone point me in the right direction?
Thanks!
(* Script ID redacted)
#include <SPI.h>
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
/////// WiFi Settings ///////
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS; // the WiFi connection status
void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial);
// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass); // connect to WPA/WPA2 network
delay(10000); // wait 10 seconds for connection
}
// print connection details
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// establish a new client connection
WiFiClient client;
const int httpPort = 443;
if (!client.connect("script.google.com", httpPort)) {
Serial.println("Connection failed");
return;
}
// send the HTTP request
client.print(String("GET ") + "/a/macros/edmarno.com/s/XXXXXXXXXXXXXX/exec?Weight=3450" + " HTTP/1.1\r\n" +
"Host: " + "script.google.com" + "\r\n" +
"Connection: close\r\n\r\n");
// wait for response
while (!client.available()) {
delay(10);
}
// read response
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// disconnect
client.stop();
delay(600000); // wait 10 minutes before repeating
}