#define BLYNK_TEMPLATE_ID "TMPLqUGcc6I7"
#define BLYNK_TEMPLATE_NAME "AG IoT Switch"
#define BLYNK_AUTH_TOKEN "E73pXWQ2I23F7Al3HnZemyX6W97sSbTD"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// GPIO where the DS18B20 is connected to
#define ONE_WIRE_BUS 16
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
char auth[] = BLYNK_AUTH_TOKEN;
//#define APP_DEBUG
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
float temp_0;
float temp_1;
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
// void myTimerEvent()
// {
// // You can send any value at any time.
// // Please don't send more that 10 values per second.
// Blynk.virtualWrite(V5, millis() / 1000);
// }
void setup()
{
// Debug console
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setCursor(0,0);
display.drawRoundRect(0, 0, 128, 64, 8, WHITE);
display.drawRoundRect(5, 5, 118, 54, 8, WHITE);
// Sets the color to black with a white background
display.setTextColor(WHITE);
display.setCursor(15,8);
display.println("Dual Temperature");
display.drawLine(6,17,120,17, WHITE);
display.setCursor(20,20);
display.println("Please connect");
display.setCursor(32,30);
display.println("the wifi...");
display.drawLine(6,40,120,40, WHITE);
display.setCursor(33,46);
display.println("R C C I I T");
display.display();
Serial.begin(115200);
Serial.println("Connecting to wifi.......");
Blynk.begin(auth, ssid, pass);
sensors.begin();
timer.setInterval(1000L, getSendData);
Serial.println(" ");
Serial.println("Testing Dual Sensor data");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Setup a function to be called every second
timer.setInterval(1000L, getSendData);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
display.clearDisplay();
display.setCursor(0,0);
display.drawRoundRect(0, 0, 128, 64, 8, WHITE);
display.drawRoundRect(5, 5, 118, 54, 8, WHITE);
// Sets the color to black with a white background
display.setTextColor(WHITE);
display.setCursor(15,8);
display.println("Dual Temperature");
display.drawLine(6,17,120,17, WHITE);
display.setCursor(10,20);
display.println("Temp 1 = ");
display.setCursor(10,30);
display.println("Temp 2 = ");
display.setCursor(65,20);
display.println(temp_0, 4);
display.setCursor(110,20);
display.print((char)247); // degree symbol
display.println("C");
display.setCursor(65,30);
display.println(temp_1, 4);
display.setCursor(110,30);
display.print((char)247); // degree symbol
display.println("C");
display.drawLine(6,40,120,40, WHITE);
display.setCursor(33,46);
display.println("R C C I I T");
display.display();
}
/***************************************************
* Send Sensor data to Blynk
**************************************************/
void getSendData()
{
sensors.requestTemperatures();
temp_0 = sensors.getTempCByIndex(0); // Sensor 0 will capture Temp in Celcius
temp_1 = sensors.getTempCByIndex(1); // Sensor 0 will capture Temp in Celcius
Serial.print("Temp_0: ");
Serial.print(temp_0, 4);
Serial.print(" oC . Temp_1: ");
Serial.print(temp_1, 4);
Serial.println(" oC");
Blynk.virtualWrite(10, temp_0); //virtual pin V10
Blynk.virtualWrite(11, temp_1); //virtual pin V11
}