Skip to content

Commit b1e46fa

Browse files
committed
Merge branch 'master' of https://github.com/Sparow199/EspruinoDocs into Sparow199-master
2 parents 33cee62 + 970e0ce commit b1e46fa

File tree

1 file changed

+59
-58
lines changed

1 file changed

+59
-58
lines changed

modules/InfluxDB.md

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Simple [InfluxDB] wrapper for [Espruino].
1010

1111
InfluxDB is an open-source time series database developed by InfluxData. It is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics. It also has support for processing data from Graphite.
1212

13-
## Requirement
13+
Requirement
14+
-----------
1415
1- InfluxDB working server, see [installation] guide.
1516

16-
## Usage
17-
17+
Usage
18+
-----
1819
1- Configuration
1920
```
2021
// InfluxDB configuration
@@ -51,8 +52,8 @@ influxDB.query(query);
5152
console.log("Database created");
5253
```
5354

54-
## Example
55-
55+
Example
56+
-------
5657
1- Setup InfluxDB on Espruino.
5758

5859
2- Create a new InfluxDB database (from Espruino).
@@ -62,59 +63,59 @@ console.log("Database created");
6263
4- Read data from InfluxDB.
6364

6465

65-
```
66-
// Import and connect MQ135 module
67-
var mq135 = require("MQ135").connect(A0);
68-
69-
// InfluxDB configuration
70-
var influxDBParams = {
71-
influxDBHost: "localhost",
72-
influxPort: 8086,
73-
influxDBName: "testDataBase",
74-
influxUserName: "toto",
75-
influxPassword: "root",
76-
influxAgentName: "ESPRUINO"
77-
};
78-
79-
// Import and setup InfluxDB module
80-
var influxDB = require("InfluxDB").setup(influxDBParams);
81-
82-
// Create new influxDb database called "smoke" (if it's not already exists)
83-
var queryNewDB = "q=CREATE DATABASE smoke\n";
84-
try {
85-
influxDB.query(queryNewDB);
86-
console.log("Database was created");
87-
} catch (e) {
88-
console.log("Failed, unable to create the database");
89-
}
90-
91-
// Write data to InfluxDB database every 10 seconds.
92-
var writeInterval = setInterval(function() {
93-
var data = "";
94-
try {
95-
// Multiple points writing (important: separator "\n").
96-
for (var i = 0; i < 3; i++) {
97-
var smoke = mq1235.getPPM();
98-
data += "smoke, device=ESP0001, value=" + smoke + "\n";
99-
}
100-
101-
influxDB.write(data);
102-
return true;
103-
} catch (e) {
104-
console.log(e);
105-
}
106-
}, 10000);
107-
108-
// Get data to InfluxDB database every hour.
109-
var readInterval = setInterval(function() {
110-
try {
111-
var query = "q=SELECT \"value\" FROM \"measurement\"\n";
112-
var data = influxDB.query(query);
113-
console.log(data);
114-
} catch (e) {
115-
console.log(e);
116-
}
117-
}, 3600000);
66+
```js
67+
// Import and connect MQ135 module
68+
var mq135 = require("MQ135").connect(A0);
69+
70+
// InfluxDB configuration
71+
var influxDBParams = {
72+
influxDBHost: "localhost",
73+
influxPort: 8086,
74+
influxDBName: "testDataBase",
75+
influxUserName: "toto",
76+
influxPassword: "root",
77+
influxAgentName: "ESPRUINO"
78+
};
79+
80+
// Import and setup InfluxDB module
81+
var influxDB = require("InfluxDB").setup(influxDBParams);
82+
83+
// Create new influxDb database called "smoke" (if it's not already exists)
84+
var queryNewDB = "q=CREATE DATABASE smoke\n";
85+
try {
86+
influxDB.query(queryNewDB);
87+
console.log("Database was created");
88+
} catch (e) {
89+
console.log("Failed, unable to create the database");
90+
}
91+
92+
// Write data to InfluxDB database every 10 seconds.
93+
var writeInterval = setInterval(function() {
94+
var data = "";
95+
try {
96+
// Multiple points writing (important: separator "\n").
97+
for (var i = 0; i < 3; i++) {
98+
var smoke = mq135.getPPM();
99+
data += "smoke, device=ESP0001, value=" + smoke + "\n";
100+
}
101+
102+
influxDB.write(data);
103+
return true;
104+
} catch (e) {
105+
console.log(e);
106+
}
107+
}, 10000);
108+
109+
// Get data to InfluxDB database every hour.
110+
var readInterval = setInterval(function() {
111+
try {
112+
var query = "q=SELECT \"value\" FROM \"measurement\"\n";
113+
var data = influxDB.query(query);
114+
console.log(data);
115+
} catch (e) {
116+
console.log(e);
117+
}
118+
}, 3600000);
118119
```
119120

120121

0 commit comments

Comments
 (0)