Hello everyone !
I'm triggering a webhook to make.com from my Arduino MKR 1010. With WifiNina librairie it sends a ssl request and it triggers perfectly the webhook.
I would like to send a variable to be able to use it later. In my case the température of a sensor. It should look like that : https://hook.eu1.make.com/{mykey}?variable but I don't know the synthax of adding the varible at the end in my case.
He is the isolate code of the html request:
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /mbvbogobiXXXXXXXXXXwu6oz HTTP/1.1");
client.println("Host: hook.eu1.make.com");
client.println("Connection: close");
client.println();
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
}
}
And here is my entire code:
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/b632f186-68af-4a8b-be8e-8684bbd3bc6f
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudTemperatureSensor temp_fermenter1;
CloudTemperatureSensor temp_TAL;
int tAL_temp_alert;
bool tAL_alert_status;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <SPI.h>
#include <WiFiNINA.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to GPI2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1 = { 0x28, 0xCA, 0x6, 0x49, 0xF6, 0x55, 0x3C, 0x68 };
DeviceAddress sensor2 = { 0x28, 0x3E, 0x6E, 0x49, 0xF6, 0x1F, 0x3C, 0x95 };
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_OPTIONAL_PASS; // 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 temp_time_mark = millis(); //variable to store a millis
int temp_check_time = 1000; // Number of millisecond betzeen two temp check
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)
char server[] = "hook.eu1.make.com";
// 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);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// 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 5 seconds for connection:
delay(5000);
}
Serial.println("Connected to WiFi");
printWiFiStatus();
}
void loop() {
ArduinoCloud.update();
// Your code here
if(millis()- temp_time_mark>=temp_check_time){
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Sensor 1(*C): ");
Serial.println(sensors.getTempC(sensor1));
temp_TAL = sensors.getTempC(sensor1);
Serial.println("Température d'alerte: ");
Serial.println(tAL_temp_alert);
temp_fermenter1 = sensors.getTempC(sensor2);
Serial.print("Sensor 2(*C): ");
Serial.println(sensors.getTempC(sensor2));
if (temp_TAL >= tAL_temp_alert){
tAL_alert_status = false;
Serial.print("temp_TAL: ");
Serial.println(temp_TAL);
Serial.print("Envoi de la notification Push...");
push_notif();
}
else{
tAL_alert_status = true;
}
temp_time_mark=millis(); //reseting the time mark
}
}
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");
}
void push_notif(){
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /mbvbogobiXXXXXXXXwu6oz HTTP/1.1");
client.println("Host: hook.eu1.make.com");
client.println("Connection: close");
client.println();
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
}
}
}
/*
Since TALTempAlert is READ_WRITE variable, onTALTempAlertChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTALTempAlertChange() {
// Add your code here to act upon TALTempAlert change
}
/*
Since TALAlertStatus is READ_WRITE variable, onTALAlertStatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTALAlertStatusChange() {
}