-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrodaiSensorBlynk.ino
97 lines (73 loc) · 2.73 KB
/
rodaiSensorBlynk.ino
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
88
89
90
91
92
93
94
95
96
97
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
// #define BLYNK_DEBUG // Optional, this enables more detailed prints
/*Comment #include "config.h"*/
#include "config.h"
/*Change your parameter*/
#define BLYNK_TEMPLATE_ID BLYNK_TEMPLATE_ID_OWNER
#define BLYNK_DEVICE_NAME BLYNK_DEVICE_NAME_OWNER
#define BLYNK_AUTH_TOKEN BLYNK_AUTH_TOKEN_OWNER
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "RodaiSensor.h"
#include "esp_log.h"
#define SOIL_SENSOR_1 V5
#define SOIL_SENSOR_2 V6
#define SOIL_SENSOR_3 V7
#define SOIL_SENSOR_4 V8
#define AMBIENT_TEMPERATURE_SENSOR V20
#define AMBIENT_HUMIDITY_SENSOR V21
#define LIGHT_SENSOR V25
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
/*Change your parameter*/
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = WIFI_SSID;
char pass[] = WIFI_PASS;
#define RS485_PORT UART_NUM_1
#define RS485_TX GPIO_NUM_23
#define RS485_RX GPIO_NUM_22
#define RS485_DIR GPIO_NUM_4
#define RS485_CTS UART_PIN_NO_CHANGE
#define RS485_BAUDRATE 9600
BlynkTimer timer;
RodaiSensor rodaiSensor = RodaiSensor(RS485_PORT, RS485_TX, RS485_RX, RS485_DIR, RS485_CTS, RS485_BAUDRATE);
// 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.
int soil1 = rodaiSensor.getRodaiSoilWaterContentValue(16);
ESP_LOGI("MAIN", "soil1= %f", (float)soil1 / 1000.0f);
Blynk.virtualWrite(SOIL_SENSOR_1, (float)soil1 / 1000.0f);
int soil2 = rodaiSensor.getRodaiSoilWaterContentValue(17);
ESP_LOGI("MAIN", "soil2= %f", (float)soil2 / 1000.0f);
Blynk.virtualWrite(SOIL_SENSOR_2, (float)soil2 / 1000.0f);
int soil3 = rodaiSensor.getRodaiSoilWaterContentValue(18);
ESP_LOGI("MAIN", "soil3= %f", (float)soil3 / 1000.0f);
Blynk.virtualWrite(SOIL_SENSOR_3, (float)soil3 / 1000.0f);
int soil4 = rodaiSensor.getRodaiSoilWaterContentValue(19);
ESP_LOGI("MAIN", "soil4= %f", (float)soil4 / 1000.0f);
Blynk.virtualWrite(SOIL_SENSOR_4, (float)soil4 / 1000.0f);
Blynk.virtualWrite(AMBIENT_TEMPERATURE_SENSOR, 35.64f);
Blynk.virtualWrite(AMBIENT_HUMIDITY_SENSOR, 75.62f);
Blynk.virtualWrite(LIGHT_SENSOR, 4324);
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// Setup a function to be called every second
timer.setInterval(5000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}