#include <stdio.h>
#include <string.h>
#include <ESP32WiFi.h> // Assuming ESP32 platform
#include <HTTPClient.h>
const char* WIFI_SSID = "your_wifi_ssid";
const char* WIFI_PASSWORD = "your_wifi_password";
const char* TS_API_ENDPOINT = "https://api.thingspeak.com/update";
const char* WRITE_API_KEY = "your_thingspeak_write_api_key";
int inventory_level = 100;
int temperature = 25;
void connectToWiFi() {
Serial.println("Connecting to WiFi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void sendDataToThingSpeak() {
HTTPClient http;
String payload = "api_key=" + String(WRITE_API_KEY) + "&field1=" +
String(inventory_level) + "&field2=" + String(temperature);
Serial.print("Sending data to ThingSpeak... ");
http.begin(TS_API_ENDPOINT);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpResponseCode = http.POST(payload);
if(httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode); }