Skip to content

Commit ce9a552

Browse files
committed
Added two samples.
1 parent 14e6b37 commit ce9a552

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
#include <ESP8266WiFi.h>
3+
#include <ESP8266WiFiMulti.h>
4+
#include <InfluxDb.h>
5+
6+
#define INFLUXDB_HOST "192.168.0.32"
7+
#define WIFI_SSID "xxx"
8+
#define WIFI_PASS "xxx"
9+
10+
ESP8266WiFiMulti WiFiMulti;
11+
Influxdb influx(INFLUXDB_HOST);
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
Serial.println(" ### Hello ###");
16+
17+
WiFiMulti.addAP(WIFI_SSID, WIFI_PASS);
18+
Serial.print("Connecting to WIFI");
19+
while (WiFiMulti.run() != WL_CONNECTED) {
20+
Serial.print(".");
21+
delay(100);
22+
}
23+
Serial.println("WiFi connected");
24+
Serial.println("IP address: ");
25+
Serial.println(WiFi.localIP());
26+
27+
influx.setDb("test");
28+
29+
Serial.println("Setup done");
30+
}
31+
32+
33+
int loopCount = 0;
34+
35+
void loop() {
36+
loopCount++;
37+
38+
InfluxData m1 = measure(1);
39+
influx.prepare(m1);
40+
41+
InfluxData m2 = measure(2);
42+
influx.prepare(m2);
43+
44+
InfluxData m3 = measure(3);
45+
influx.prepare(m3);
46+
47+
// only with this call all prepared measurements are sent
48+
influx.write();
49+
50+
delay(5000);
51+
}
52+
53+
/**
54+
Just create a random measurement.
55+
*/
56+
InfluxData measure(int number) {
57+
InfluxData row("temperature");
58+
row.addTag("device", "alpha");
59+
row.addTag("sensor", "one");
60+
row.addTag("mode", "pwm");
61+
row.addValue("number", number);
62+
row.addValue("loopCount", loopCount);
63+
row.addValue("value", random(10, 40));
64+
return row;
65+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
#include <ESP8266WiFi.h>
3+
#include <ESP8266WiFiMulti.h>
4+
#include <InfluxDb.h>
5+
6+
#define INFLUXDB_HOST "192.168.0.32"
7+
#define WIFI_SSID "xxx"
8+
#define WIFI_PASS "xxx"
9+
10+
ESP8266WiFiMulti WiFiMulti;
11+
Influxdb influx(INFLUXDB_HOST);
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
Serial.println(" ### Hello ###");
16+
17+
WiFiMulti.addAP(WIFI_SSID, WIFI_PASS);
18+
Serial.print("Connecting to WIFI");
19+
while (WiFiMulti.run() != WL_CONNECTED) {
20+
Serial.print(".");
21+
delay(100);
22+
}
23+
Serial.println("WiFi connected");
24+
Serial.println("IP address: ");
25+
Serial.println(WiFi.localIP());
26+
27+
influx.setDb("test");
28+
29+
Serial.println("Setup done");
30+
}
31+
32+
33+
int loopCount = 0;
34+
35+
void loop() {
36+
loopCount++;
37+
38+
InfluxData row("temperature");
39+
row.addTag("device", "alpha");
40+
row.addTag("sensor", "one");
41+
row.addTag("mode", "pwm");
42+
row.addValue("loopCount", loopCount);
43+
row.addValue("value", random(10, 40));
44+
45+
influx.write(row);
46+
47+
delay(5000);
48+
}

0 commit comments

Comments
 (0)