Code: Select all
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <TFT_eSPI.h>
const char* ssid = "xxxxx"; // Nazwa WiFi
const char* password = "xxxx"; // Hasło Wifi
const char* host1 = "Link odczyt"; // Supla Direct Link Temp
// Piny TFT
#define TFT_CS 27
#define TFT_DC 25
#define TFT_RST 32
// Piny SPI
#define PIN_MOSI 23 // GPIO 23
#define PIN_MISO 19 // GPIO 19
#define PIN_SCK 18 // GPIO 18
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(115200);
// Initialize TFT display
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
// Initialize SPI interface
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
// Make HTTP GET request
HTTPClient http;
http.begin(host1);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String payload = http.getString();
// Parse JSON
const size_t capacity = JSON_OBJECT_SIZE(3) + 50;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);
// Extract data from JSON
const char* temp1 = doc["temp1"];
// Display data on TFT
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.setTextColor(TFT_BLACK); // Zmiana koloru napisów na czarny
tft.println("Supla Data:");
tft.println("-----------------");
tft.print("Temperature 1: ");
tft.println(temp1);
} else {
Serial.print("Error in HTTP request. Error code: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("WiFi Disconnected");
}
delay(5000); // Wait for 5 seconds before making the next request
}