-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdated_functions.cpp
More file actions
87 lines (73 loc) · 2.76 KB
/
updated_functions.cpp
File metadata and controls
87 lines (73 loc) · 2.76 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
83
84
85
86
87
#ifdef USE_MESHTASTIC
// Send data to Meshtastic node using the toRadio API endpoint with proper protobuf structure
void sendDataToMeshtastic(float temperature, float humidity, float rainAmount) {
Serial.println("Preparing data for Meshtastic node...");
// Get Meshtastic configuration
WeatherStationConfig* config = configManager.getConfig();
// Create JSON document for the weather data
StaticJsonDocument<256> dataDoc;
// Include temperature data
dataDoc["temperature"] = temperature;
// Include sensor-specific data
#ifdef USE_DHT22
dataDoc["humidity"] = humidity;
dataDoc["sensor"] = "DHT22";
#endif
// When both I2C sensors are used, we get more complete data
#if defined(USE_AHT20) && defined(USE_BMP280)
dataDoc["humidity"] = humidity;
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
dataDoc["pressure"] = pressure;
dataDoc["sensor"] = "AHT20+BMP280";
#elif defined(USE_AHT20)
dataDoc["humidity"] = humidity;
dataDoc["sensor"] = "AHT20";
#elif defined(USE_BMP280)
dataDoc["pressure"] = bmp.readPressure() / 100.0F; // Convert Pa to hPa
dataDoc["sensor"] = "BMP280";
#endif
// Include rain data and node identification
dataDoc["rain"] = rainAmount;
dataDoc["rain_1h"] = getRainLastHour();
dataDoc["rain_24h"] = getRainLast24Hours();
dataDoc["node_name"] = config->deviceName;
// Serialize weather data JSON to string
String dataString;
serializeJson(dataDoc, dataString);
Serial.print("Weather data: ");
Serial.println(dataString);
}
#endif // USE_MESHTASTIC
#ifdef USE_MQTT
// Function to send data via MQTT
bool sendDataToMQTT(float temperature, float humidity, float rainAmount) {
// Código até a parte do JSON...
// Create JSON document for the weather data
StaticJsonDocument<256> dataDoc;
// Include temperature data
dataDoc["temperature"] = temperature;
// Include sensor-specific data
#ifdef USE_DHT22
dataDoc["humidity"] = humidity;
dataDoc["sensor"] = "DHT22";
#endif
// When both I2C sensors are used, we get more complete data
#if defined(USE_AHT20) && defined(USE_BMP280)
dataDoc["humidity"] = humidity;
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
dataDoc["pressure"] = pressure;
dataDoc["sensor"] = "AHT20+BMP280";
#elif defined(USE_AHT20)
dataDoc["humidity"] = humidity;
dataDoc["sensor"] = "AHT20";
#elif defined(USE_BMP280)
dataDoc["pressure"] = bmp.readPressure() / 100.0F; // Convert Pa to hPa
dataDoc["sensor"] = "BMP280";
#endif
// Include rain data and node identification
dataDoc["rain"] = rainAmount;
dataDoc["rain_1h"] = getRainLastHour();
dataDoc["rain_24h"] = getRainLast24Hours();
dataDoc["node_name"] = config->deviceName;
}
#endif // USE_MQTT