-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfluxSensor.ino
63 lines (48 loc) · 1.45 KB
/
InfluxSensor.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
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <string.h>
#include "utils/influx.h"
#include "utils/ota.h"
#include "utils/wifimanager.h"
#include <ArduinoOTA.h>
#include <vector>
#include "../secrets_example.h"
using std::vector;
// OTA ota;
CustomWifiManager wfm;
Influx influx;
// const char *ssid = STASSID;
// const char *password = STAPSK;
const int AirValue = 750; //you need to replace this value with Value_1
const int WaterValue = 325;
int getSoilMoistureValue()
{
return map(analogRead(A0), WaterValue, AirValue, 0, 100);
}
void setup()
{
// Add params to wifiManager.
wfm.add_param("node_id", "Node ID", "basil-1", 60);
wfm.add_param("influx_bucket", "Influx Bucket", "bucket-2", 60);
wfm.add_param("influx_token", "Influx Token", "S8u.....", 89);
wfm.add_param("influx_url", "Influx Url", "https://us-central1-1.gcp.cloud2.influxdata.com", 89);
wfm.add_param("influx_org", "Influx Org", "[email protected]", 60);
wfm.setup_wifi_manager();
// Add sensors to Influx
Sensor soilMoisture("soil_moisture", "wetness", getSoilMoistureValue);
Serial.println("NODE_ID");
Serial.println(wfm.getParamValue("node_id"));
// Add tags
soilMoisture.addTag("node_id", (String)wfm.getParamValue("node_id"));
influx.add_sensor(soilMoisture);
// ota.setup_ota(ssid, password);
influx.setup_influx("ESP8266");
}
void loop()
{
// ota.handle_ota();
wfm.do_loop();
influx.run_influx();
delay(3000);
}