The Internet of Things, or IoT, is a system of interrelated computing devices, mechanical and digital machines, objects, animals or people that are provided with unique identifiers (UIDs) and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction.
A thing in the internet of things can be a person with a heart monitor implant, a farm animal with a biochip transponder, an automobile that has built-in sensors to alert the driver when tire pressure is low or any other natural or man-made object that can be assigned an Internet Protocol (IP) address and is able to transfer data over a network.
Acera Wifi: AceraStudent. PW= daisyJet91
ESP32 Publish Sensor Readings to Thingspeak
https://randomnerdtutorials.com/esp32-thingspeak-publish-arduino/
Write API Key: AC702TNVD5X4CCO9
Read API Key. 3V2UUA1Y3TBDWVNU
Channel ID. 2414066
#define motorPin 9
//------------------------------
#include <DHT22.h>
#define pinDATA 3 // Digital pin D3
DHT22 dht22(pinDATA);
//-----------------------------------
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
// I2C address for most SH1106 displays
#define I2C_ADDRESS 0x3C
// Create display object (128x64 SH1106)
Adafruit_SH1106G display(128, 64, &Wire);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Most 0.96" OLEDs are address 0x3C. If yours is 0x3D, change it.
#define OLED_ADDR 0x3C
#include <WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Initialize our values
int number1 = 20;
int number2 = 20;
int number3 = 20;
String myStatus = "";
void setup() {
Serial.begin(115200); //Initialize serial
Serial.println("\ntest capteur DTH22");
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
Wire.begin();
// Initialize display
if (!display.begin(I2C_ADDRESS, true)) {
while (1); // Stop if display fails
}
display.clearDisplay();
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
sensorValue=map(sensorValue, 40, 1000, 0, 200); //change range of value
Serial.println(sensorValue);
analogWrite(motorPin, sensorValue);
delay(1000); // delay in between reads for stability
//-------------------------------------
float t = dht22.getTemperature();
float h = dht22.getHumidity();
if (dht22.getLastError() != dht22.OK) {
Serial.print("last error :");
Serial.println(dht22.getLastError());
}
//------------------------------------------------------
Serial.print("h=");Serial.print(h,1);Serial.print("\t");
Serial.print("t=");Serial.println(t,1);
delay(2000); //Collecting period should be : >1.7 second
// nothing needed
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
display.clearDisplay();
// Set text properties
display.setTextSize(2);
display.setTextColor(SH110X_WHITE);
display.setCursor(0,0);
display.print("T= "); // x, y (top-left)
display.println(t);
display.print("H= ");
display.println(h);
display.print("L= ");
display.println(sensorValue);
display.display(); // push to screen
// set the fields with the values
ThingSpeak.setField(1, t);
ThingSpeak.setField(2, sensorValue);
ThingSpeak.setField(3, h);
// set the status
ThingSpeak.setStatus(myStatus);
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
delay(20000); // Wait 20 seconds to update the channel again
}