Repository navigation
Expand file tree
/
Copy pathExample.ino
More file actions
82 lines (65 loc) · 2.59 KB
/
Copy pathExample.ino
File metadata and controls
82 lines (65 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <WiFi.h>
#include <GS32ReportWeb.h>
// Данные вашей сети Wi-Fi
const char* ssid = "GS32Report";
const char* password = "11112222";
// Адрес вашего сервера (например, webhook.site для тестов или ваш бэкенд)
const char* serverUrl = "https://piminoff.ru/server.php";
// Создаем объект библиотеки
GS32ReportWeb reporter;
// Функция для добавления пользовательских данных (например, датчиков или счетчиков)
void addMyCustomData(JsonObject& custom) {
// Добавим фальшивые данные датчиков (или ваши реальные DHT22)
custom["temperature"] = 23.5;
custom["humidity"] = 58.2;
custom["device_status"] = "OK";
custom["reboots_count"] = 3;
}
void setup() {
Serial.begin(115200);
delay(1000);
// Подключение к Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
int attempt = 0;
// Ждем подключения до 20 секунд
while (WiFi.status() != WL_CONNECTED && attempt < 40) {
delay(500);
Serial.print(".");
attempt++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\n[WiFi] Connected!");
Serial.print("[WiFi] IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("\n[WiFi] Connection Failed! Check power or credentials.");
}
reporter.begin(serverUrl);
// 1. Настройка того, какие системные параметры мы хотим передавать
SystemReportConfig myConfig;
reporter.chipModel(true);
reporter.chipId(true);
reporter.heap(true);
reporter.uptime(true);
// Отключим то, что нам не нужно
reporter.flashSpeed(false);
reporter.sdkVersion(false);
reporter.sketchSize(false);
reporter.setConfig(myConfig);
// 2. Регистрируем пользовательские данные
reporter.onCustomData(addMyCustomData);
}
void loop() {
unsigned long currentMillis = millis();
// Проверка переподключения к WiFi
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi lost. Reconnecting...");
WiFi.begin(ssid, password);
}
Serial.println(WiFi.localIP());
// Отправляем отчет каждые 3 секунды
Serial.println("\n--- Sending Report ---");
reporter.sendReport();
delay(3000);
}