node-red-contrib-influxdb3 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +386 -386
- package/__tests__/influxdb3.test.js +786 -240
- package/examples/basic-flow.json +170 -170
- package/examples/mqtt-to-influx.json +134 -134
- package/influxdb3.html +243 -243
- package/influxdb3.js +458 -315
- package/package.json +41 -44
- package/renovate.json +6 -6
- package/test/line-protocol-validation.test.js +83 -0
- package/test/point-api.test.js +56 -0
package/README.md
CHANGED
|
@@ -1,386 +1,386 @@
|
|
|
1
|
-
# node-red-contrib-influxdb3
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/node-red-contrib-influxdb3)
|
|
4
|
-
[](https://www.npmjs.com/package/node-red-contrib-influxdb3)
|
|
5
|
-
[](https://flows.nodered.org/node/node-red-contrib-influxdb3)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
|
|
8
|
-
Node-RED nodes for writing data to InfluxDB v3.
|
|
9
|
-
|
|
10
|
-
This package provides Node-RED integration with InfluxDB v3 using the official [@influxdata/influxdb3-client](https://github.com/InfluxCommunity/influxdb3-js) JavaScript library.
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
### From npm (when published)
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
cd ~/.node-red
|
|
18
|
-
npm install node-red-contrib-influxdb3
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### From local directory
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
cd ~/.node-red
|
|
25
|
-
npm install /path/to/node-red-contrib-influxdb3
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Development Installation
|
|
29
|
-
|
|
30
|
-
1. Clone this repository
|
|
31
|
-
2. Install dependencies:
|
|
32
|
-
```bash
|
|
33
|
-
npm install
|
|
34
|
-
```
|
|
35
|
-
3. Link to your Node-RED installation:
|
|
36
|
-
```bash
|
|
37
|
-
cd ~/.node-red
|
|
38
|
-
npm install /path/to/node-red-contrib-influxdb3
|
|
39
|
-
```
|
|
40
|
-
4. Restart Node-RED
|
|
41
|
-
|
|
42
|
-
## Nodes
|
|
43
|
-
|
|
44
|
-
This package includes two nodes:
|
|
45
|
-
|
|
46
|
-
### InfluxDB v3 Config Node
|
|
47
|
-
|
|
48
|
-
A configuration node that stores connection details for your InfluxDB v3 instance.
|
|
49
|
-
|
|
50
|
-
**Configuration:**
|
|
51
|
-
- **Name**: A friendly name for the connection
|
|
52
|
-
- **Host**: Your InfluxDB v3 host URL (e.g., `https://us-east-1-1.aws.cloud2.influxdata.com`)
|
|
53
|
-
- **Token**: Your InfluxDB v3 authentication token
|
|
54
|
-
- **Database**: The default database (bucket) name
|
|
55
|
-
- **Verify TLS**: Toggle TLS certificate verification (unchecked sets `NODE_TLS_REJECT_UNAUTHORIZED=0`)
|
|
56
|
-
- **CA Cert Path**: Optional filesystem path for a custom root CA (`NODE_EXTRA_CA_CERTS`)
|
|
57
|
-
|
|
58
|
-
### InfluxDB v3 Write Node
|
|
59
|
-
|
|
60
|
-
Writes data points to InfluxDB v3.
|
|
61
|
-
|
|
62
|
-
**Configuration:**
|
|
63
|
-
- **Connection**: Select an InfluxDB v3 config node
|
|
64
|
-
- **Name**: Optional node name
|
|
65
|
-
- **Measurement**: Default measurement name (can be overridden by `msg.measurement`)
|
|
66
|
-
- **Database**: Optional database override (uses connection default if not set)
|
|
67
|
-
|
|
68
|
-
## Usage
|
|
69
|
-
|
|
70
|
-
### Input Message Formats
|
|
71
|
-
|
|
72
|
-
The write node accepts data in multiple formats:
|
|
73
|
-
|
|
74
|
-
#### 1. Line Protocol String
|
|
75
|
-
|
|
76
|
-
Send data as a string in InfluxDB line protocol format:
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
msg.payload = "temperature,location=room1 value=21.5";
|
|
80
|
-
return msg;
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
#### 2. Object with Fields and Tags
|
|
84
|
-
|
|
85
|
-
Send an object with explicit `fields` and `tags` properties:
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
msg.measurement = "temperature";
|
|
89
|
-
msg.payload = {
|
|
90
|
-
fields: {
|
|
91
|
-
value: 21.5,
|
|
92
|
-
humidity: 65
|
|
93
|
-
},
|
|
94
|
-
tags: {
|
|
95
|
-
location: "room1",
|
|
96
|
-
sensor: "dht22"
|
|
97
|
-
},
|
|
98
|
-
timestamp: Date.now() // optional
|
|
99
|
-
};
|
|
100
|
-
return msg;
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### 3. Simplified Object Format
|
|
104
|
-
|
|
105
|
-
Send an object where all properties (except 'tags' and 'timestamp') are treated as fields:
|
|
106
|
-
|
|
107
|
-
```javascript
|
|
108
|
-
msg.measurement = "environment";
|
|
109
|
-
msg.payload = {
|
|
110
|
-
temperature: 21.5,
|
|
111
|
-
humidity: 65,
|
|
112
|
-
pressure: 1013.25,
|
|
113
|
-
tags: {
|
|
114
|
-
room: "bedroom",
|
|
115
|
-
floor: "2"
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return msg;
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Data Types
|
|
122
|
-
|
|
123
|
-
**Important:** By default, **all numbers are written as floats** to avoid schema conflicts in InfluxDB. This is because JavaScript doesn't distinguish between `1.0` and `1` (both equal `1`), which can cause issues when InfluxDB expects a float but receives an integer.
|
|
124
|
-
|
|
125
|
-
When using object format, the node handles data types as follows:
|
|
126
|
-
- **Numbers**: Written as **float fields** by default
|
|
127
|
-
- **Integers**: Must be explicitly marked (see below)
|
|
128
|
-
- **Booleans**: Written as boolean fields
|
|
129
|
-
- **Strings**: Written as string fields
|
|
130
|
-
- **Tags**: Always converted to strings
|
|
131
|
-
|
|
132
|
-
#### Writing Integer Fields
|
|
133
|
-
|
|
134
|
-
To write integers explicitly, use one of these methods:
|
|
135
|
-
|
|
136
|
-
**Method 1: Using the `integers` array**
|
|
137
|
-
```javascript
|
|
138
|
-
msg.payload = {
|
|
139
|
-
fields: {
|
|
140
|
-
temperature: 21.5, // float
|
|
141
|
-
count: 42, // will be float by default
|
|
142
|
-
total: 100 // will be float by default
|
|
143
|
-
},
|
|
144
|
-
integers: ['count', 'total'] // mark these as integers
|
|
145
|
-
};
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
**Method 2: Using the `i` suffix**
|
|
149
|
-
```javascript
|
|
150
|
-
msg.payload = {
|
|
151
|
-
fields: {
|
|
152
|
-
temperature: 21.5, // float
|
|
153
|
-
count: "42i", // integer (note the string with 'i' suffix)
|
|
154
|
-
total: "100i" // integer
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
**Example with both floats and integers:**
|
|
160
|
-
```javascript
|
|
161
|
-
msg.measurement = "sensor_data";
|
|
162
|
-
msg.payload = {
|
|
163
|
-
temperature: 21.5, // float
|
|
164
|
-
humidity: 65.0, // float (even though it looks like an integer)
|
|
165
|
-
event_count: "50i", // integer
|
|
166
|
-
tags: {
|
|
167
|
-
location: "room1"
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Message Properties
|
|
173
|
-
|
|
174
|
-
The following message properties can be used to override node configuration:
|
|
175
|
-
|
|
176
|
-
- `msg.measurement` - Override the measurement name
|
|
177
|
-
- `msg.database` - Override the database name
|
|
178
|
-
- `msg.timestamp` - Set the timestamp for the data point (Date object or milliseconds)
|
|
179
|
-
- `msg.payload.integers` - Array of field names to write as integers (e.g., `['count', 'total']`)
|
|
180
|
-
|
|
181
|
-
## Examples
|
|
182
|
-
|
|
183
|
-
### Example 1: Temperature Sensor
|
|
184
|
-
|
|
185
|
-
```javascript
|
|
186
|
-
// Function node
|
|
187
|
-
msg.measurement = "temperature";
|
|
188
|
-
msg.payload = {
|
|
189
|
-
value: 21.5,
|
|
190
|
-
tags: {
|
|
191
|
-
location: "living_room",
|
|
192
|
-
sensor_id: "temp_001"
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
return msg;
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Example 2: Multi-Sensor Data
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
// Function node
|
|
202
|
-
msg.measurement = "environment";
|
|
203
|
-
msg.payload = {
|
|
204
|
-
fields: {
|
|
205
|
-
temperature: 22.3,
|
|
206
|
-
humidity: 58,
|
|
207
|
-
co2: 412,
|
|
208
|
-
light: 850
|
|
209
|
-
},
|
|
210
|
-
tags: {
|
|
211
|
-
room: "office",
|
|
212
|
-
floor: "3",
|
|
213
|
-
building: "A"
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
return msg;
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### Example 3: MQTT to InfluxDB
|
|
220
|
-
|
|
221
|
-
```
|
|
222
|
-
[MQTT In] --> [JSON Parse] --> [Function] --> [InfluxDB v3 Write]
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Function node:
|
|
226
|
-
```javascript
|
|
227
|
-
// Parse MQTT topic for location
|
|
228
|
-
const location = msg.topic.split('/')[1];
|
|
229
|
-
|
|
230
|
-
msg.measurement = "sensor_data";
|
|
231
|
-
msg.payload = {
|
|
232
|
-
temperature: msg.payload.temp,
|
|
233
|
-
humidity: msg.payload.hum,
|
|
234
|
-
tags: {
|
|
235
|
-
location: location
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
return msg;
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Example 4: Using Line Protocol
|
|
242
|
-
|
|
243
|
-
```javascript
|
|
244
|
-
// Function node - direct line protocol
|
|
245
|
-
const location = "warehouse";
|
|
246
|
-
const temp = 18.5;
|
|
247
|
-
const humidity = 72;
|
|
248
|
-
|
|
249
|
-
msg.payload = `climate,location=${location} temperature=${temp},humidity=${humidity}`;
|
|
250
|
-
return msg;
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Example 5: Multiple Databases
|
|
254
|
-
|
|
255
|
-
```javascript
|
|
256
|
-
// Write to different databases based on data type
|
|
257
|
-
if (msg.payload.type === "critical") {
|
|
258
|
-
msg.database = "critical-events";
|
|
259
|
-
} else {
|
|
260
|
-
msg.database = "general-logs";
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
msg.measurement = "events";
|
|
264
|
-
msg.payload = {
|
|
265
|
-
severity: msg.payload.severity,
|
|
266
|
-
message: msg.payload.msg,
|
|
267
|
-
tags: {
|
|
268
|
-
type: msg.payload.type
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
return msg;
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
## Sample Flow
|
|
275
|
-
|
|
276
|
-
Import this flow into Node-RED to get started:
|
|
277
|
-
|
|
278
|
-
```json
|
|
279
|
-
[
|
|
280
|
-
{
|
|
281
|
-
"id": "influxdb3-config-node",
|
|
282
|
-
"type": "influxdb3-config",
|
|
283
|
-
"name": "My InfluxDB v3",
|
|
284
|
-
"host": "https://us-east-1-1.aws.cloud2.influxdata.com",
|
|
285
|
-
"database": "my-database"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
"id": "inject-node",
|
|
289
|
-
"type": "inject",
|
|
290
|
-
"name": "Generate Data",
|
|
291
|
-
"props": [{"p": "payload"}],
|
|
292
|
-
"repeat": "5",
|
|
293
|
-
"topic": "",
|
|
294
|
-
"payload": "",
|
|
295
|
-
"payloadType": "date",
|
|
296
|
-
"x": 140,
|
|
297
|
-
"y": 100,
|
|
298
|
-
"wires": [["function-node"]]
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
"id": "function-node",
|
|
302
|
-
"type": "function",
|
|
303
|
-
"name": "Format Data",
|
|
304
|
-
"func": "msg.measurement = 'temperature';\nmsg.payload = {\n value: 20 + Math.random() * 10,\n tags: {\n location: 'office'\n }\n};\nreturn msg;",
|
|
305
|
-
"x": 320,
|
|
306
|
-
"y": 100,
|
|
307
|
-
"wires": [["influxdb3-write-node"]]
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
"id": "influxdb3-write-node",
|
|
311
|
-
"type": "influxdb3-write",
|
|
312
|
-
"name": "Write to InfluxDB",
|
|
313
|
-
"influxdb": "influxdb3-config-node",
|
|
314
|
-
"measurement": "",
|
|
315
|
-
"database": "",
|
|
316
|
-
"x": 530,
|
|
317
|
-
"y": 100,
|
|
318
|
-
"wires": [["debug-node"]]
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
"id": "debug-node",
|
|
322
|
-
"type": "debug",
|
|
323
|
-
"name": "Debug",
|
|
324
|
-
"x": 730,
|
|
325
|
-
"y": 100,
|
|
326
|
-
"wires": []
|
|
327
|
-
}
|
|
328
|
-
]
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
## Configuration with Environment Variables
|
|
332
|
-
|
|
333
|
-
You can use environment variables in the configuration node:
|
|
334
|
-
|
|
335
|
-
- `INFLUX_HOST` - InfluxDB v3 host URL
|
|
336
|
-
- `INFLUX_TOKEN` - Authentication token
|
|
337
|
-
- `INFLUX_DATABASE` - Default database name
|
|
338
|
-
|
|
339
|
-
Simply reference them in the Node-RED UI using `${INFLUX_HOST}` syntax (if using Node-RED environment variable substitution).
|
|
340
|
-
|
|
341
|
-
## Troubleshooting
|
|
342
|
-
|
|
343
|
-
### Connection Issues
|
|
344
|
-
|
|
345
|
-
- Verify your host URL is correct and includes `https://`
|
|
346
|
-
- Check that your token has write permissions for the database
|
|
347
|
-
- Ensure the database name exists in your InfluxDB v3 instance
|
|
348
|
-
|
|
349
|
-
### TLS / Custom Certificates
|
|
350
|
-
|
|
351
|
-
If you are connecting to a local InfluxDB v3 instance with a custom certificate:
|
|
352
|
-
|
|
353
|
-
- Set **CA Cert Path** in the config node to the PEM file containing your root CA. This sets `NODE_EXTRA_CA_CERTS` for the Node-RED process.
|
|
354
|
-
- As a last resort, disable **Verify TLS** to set `NODE_TLS_REJECT_UNAUTHORIZED=0` (this disables TLS verification globally for the process).
|
|
355
|
-
|
|
356
|
-
### Data Not Appearing
|
|
357
|
-
|
|
358
|
-
- Check the node status - it should show "written" briefly after successful writes
|
|
359
|
-
- Verify at least one field is provided (InfluxDB requires at least one field)
|
|
360
|
-
- Check that field values are not null or undefined
|
|
361
|
-
|
|
362
|
-
### Error Messages
|
|
363
|
-
|
|
364
|
-
The node will display error status and log details to the Node-RED debug panel:
|
|
365
|
-
- **"no config"** - The InfluxDB v3 config node is not selected
|
|
366
|
-
- **"error"** - Check the debug panel for details
|
|
367
|
-
|
|
368
|
-
## Requirements
|
|
369
|
-
|
|
370
|
-
- Node-RED v2.0.0 or higher
|
|
371
|
-
- InfluxDB v3 instance (Cloud or Edge)
|
|
372
|
-
|
|
373
|
-
## License
|
|
374
|
-
|
|
375
|
-
MIT
|
|
376
|
-
|
|
377
|
-
## Links
|
|
378
|
-
|
|
379
|
-
- [InfluxDB v3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)
|
|
380
|
-
- [InfluxDB v3 Documentation](https://docs.influxdata.com/influxdb/v3/)
|
|
381
|
-
- [Node-RED](https://nodered.org/)
|
|
382
|
-
|
|
383
|
-
## Contributing
|
|
384
|
-
|
|
385
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
386
|
-
|
|
1
|
+
# node-red-contrib-influxdb3
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/node-red-contrib-influxdb3)
|
|
4
|
+
[](https://www.npmjs.com/package/node-red-contrib-influxdb3)
|
|
5
|
+
[](https://flows.nodered.org/node/node-red-contrib-influxdb3)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
Node-RED nodes for writing data to InfluxDB v3.
|
|
9
|
+
|
|
10
|
+
This package provides Node-RED integration with InfluxDB v3 using the official [@influxdata/influxdb3-client](https://github.com/InfluxCommunity/influxdb3-js) JavaScript library.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### From npm (when published)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd ~/.node-red
|
|
18
|
+
npm install node-red-contrib-influxdb3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### From local directory
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd ~/.node-red
|
|
25
|
+
npm install /path/to/node-red-contrib-influxdb3
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Development Installation
|
|
29
|
+
|
|
30
|
+
1. Clone this repository
|
|
31
|
+
2. Install dependencies:
|
|
32
|
+
```bash
|
|
33
|
+
npm install
|
|
34
|
+
```
|
|
35
|
+
3. Link to your Node-RED installation:
|
|
36
|
+
```bash
|
|
37
|
+
cd ~/.node-red
|
|
38
|
+
npm install /path/to/node-red-contrib-influxdb3
|
|
39
|
+
```
|
|
40
|
+
4. Restart Node-RED
|
|
41
|
+
|
|
42
|
+
## Nodes
|
|
43
|
+
|
|
44
|
+
This package includes two nodes:
|
|
45
|
+
|
|
46
|
+
### InfluxDB v3 Config Node
|
|
47
|
+
|
|
48
|
+
A configuration node that stores connection details for your InfluxDB v3 instance.
|
|
49
|
+
|
|
50
|
+
**Configuration:**
|
|
51
|
+
- **Name**: A friendly name for the connection
|
|
52
|
+
- **Host**: Your InfluxDB v3 host URL (e.g., `https://us-east-1-1.aws.cloud2.influxdata.com`)
|
|
53
|
+
- **Token**: Your InfluxDB v3 authentication token
|
|
54
|
+
- **Database**: The default database (bucket) name
|
|
55
|
+
- **Verify TLS**: Toggle TLS certificate verification (unchecked sets `NODE_TLS_REJECT_UNAUTHORIZED=0`)
|
|
56
|
+
- **CA Cert Path**: Optional filesystem path for a custom root CA (`NODE_EXTRA_CA_CERTS`)
|
|
57
|
+
|
|
58
|
+
### InfluxDB v3 Write Node
|
|
59
|
+
|
|
60
|
+
Writes data points to InfluxDB v3.
|
|
61
|
+
|
|
62
|
+
**Configuration:**
|
|
63
|
+
- **Connection**: Select an InfluxDB v3 config node
|
|
64
|
+
- **Name**: Optional node name
|
|
65
|
+
- **Measurement**: Default measurement name (can be overridden by `msg.measurement`)
|
|
66
|
+
- **Database**: Optional database override (uses connection default if not set)
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Input Message Formats
|
|
71
|
+
|
|
72
|
+
The write node accepts data in multiple formats:
|
|
73
|
+
|
|
74
|
+
#### 1. Line Protocol String
|
|
75
|
+
|
|
76
|
+
Send data as a string in InfluxDB line protocol format:
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
msg.payload = "temperature,location=room1 value=21.5";
|
|
80
|
+
return msg;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### 2. Object with Fields and Tags
|
|
84
|
+
|
|
85
|
+
Send an object with explicit `fields` and `tags` properties:
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
msg.measurement = "temperature";
|
|
89
|
+
msg.payload = {
|
|
90
|
+
fields: {
|
|
91
|
+
value: 21.5,
|
|
92
|
+
humidity: 65
|
|
93
|
+
},
|
|
94
|
+
tags: {
|
|
95
|
+
location: "room1",
|
|
96
|
+
sensor: "dht22"
|
|
97
|
+
},
|
|
98
|
+
timestamp: Date.now() // optional
|
|
99
|
+
};
|
|
100
|
+
return msg;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### 3. Simplified Object Format
|
|
104
|
+
|
|
105
|
+
Send an object where all properties (except 'tags' and 'timestamp') are treated as fields:
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
msg.measurement = "environment";
|
|
109
|
+
msg.payload = {
|
|
110
|
+
temperature: 21.5,
|
|
111
|
+
humidity: 65,
|
|
112
|
+
pressure: 1013.25,
|
|
113
|
+
tags: {
|
|
114
|
+
room: "bedroom",
|
|
115
|
+
floor: "2"
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return msg;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Data Types
|
|
122
|
+
|
|
123
|
+
**Important:** By default, **all numbers are written as floats** to avoid schema conflicts in InfluxDB. This is because JavaScript doesn't distinguish between `1.0` and `1` (both equal `1`), which can cause issues when InfluxDB expects a float but receives an integer.
|
|
124
|
+
|
|
125
|
+
When using object format, the node handles data types as follows:
|
|
126
|
+
- **Numbers**: Written as **float fields** by default
|
|
127
|
+
- **Integers**: Must be explicitly marked (see below)
|
|
128
|
+
- **Booleans**: Written as boolean fields
|
|
129
|
+
- **Strings**: Written as string fields
|
|
130
|
+
- **Tags**: Always converted to strings
|
|
131
|
+
|
|
132
|
+
#### Writing Integer Fields
|
|
133
|
+
|
|
134
|
+
To write integers explicitly, use one of these methods:
|
|
135
|
+
|
|
136
|
+
**Method 1: Using the `integers` array**
|
|
137
|
+
```javascript
|
|
138
|
+
msg.payload = {
|
|
139
|
+
fields: {
|
|
140
|
+
temperature: 21.5, // float
|
|
141
|
+
count: 42, // will be float by default
|
|
142
|
+
total: 100 // will be float by default
|
|
143
|
+
},
|
|
144
|
+
integers: ['count', 'total'] // mark these as integers
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Method 2: Using the `i` suffix**
|
|
149
|
+
```javascript
|
|
150
|
+
msg.payload = {
|
|
151
|
+
fields: {
|
|
152
|
+
temperature: 21.5, // float
|
|
153
|
+
count: "42i", // integer (note the string with 'i' suffix)
|
|
154
|
+
total: "100i" // integer
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Example with both floats and integers:**
|
|
160
|
+
```javascript
|
|
161
|
+
msg.measurement = "sensor_data";
|
|
162
|
+
msg.payload = {
|
|
163
|
+
temperature: 21.5, // float
|
|
164
|
+
humidity: 65.0, // float (even though it looks like an integer)
|
|
165
|
+
event_count: "50i", // integer
|
|
166
|
+
tags: {
|
|
167
|
+
location: "room1"
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Message Properties
|
|
173
|
+
|
|
174
|
+
The following message properties can be used to override node configuration:
|
|
175
|
+
|
|
176
|
+
- `msg.measurement` - Override the measurement name
|
|
177
|
+
- `msg.database` - Override the database name
|
|
178
|
+
- `msg.timestamp` - Set the timestamp for the data point (Date object or milliseconds)
|
|
179
|
+
- `msg.payload.integers` - Array of field names to write as integers (e.g., `['count', 'total']`)
|
|
180
|
+
|
|
181
|
+
## Examples
|
|
182
|
+
|
|
183
|
+
### Example 1: Temperature Sensor
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
// Function node
|
|
187
|
+
msg.measurement = "temperature";
|
|
188
|
+
msg.payload = {
|
|
189
|
+
value: 21.5,
|
|
190
|
+
tags: {
|
|
191
|
+
location: "living_room",
|
|
192
|
+
sensor_id: "temp_001"
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
return msg;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Example 2: Multi-Sensor Data
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
// Function node
|
|
202
|
+
msg.measurement = "environment";
|
|
203
|
+
msg.payload = {
|
|
204
|
+
fields: {
|
|
205
|
+
temperature: 22.3,
|
|
206
|
+
humidity: 58,
|
|
207
|
+
co2: 412,
|
|
208
|
+
light: 850
|
|
209
|
+
},
|
|
210
|
+
tags: {
|
|
211
|
+
room: "office",
|
|
212
|
+
floor: "3",
|
|
213
|
+
building: "A"
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
return msg;
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Example 3: MQTT to InfluxDB
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
[MQTT In] --> [JSON Parse] --> [Function] --> [InfluxDB v3 Write]
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Function node:
|
|
226
|
+
```javascript
|
|
227
|
+
// Parse MQTT topic for location
|
|
228
|
+
const location = msg.topic.split('/')[1];
|
|
229
|
+
|
|
230
|
+
msg.measurement = "sensor_data";
|
|
231
|
+
msg.payload = {
|
|
232
|
+
temperature: msg.payload.temp,
|
|
233
|
+
humidity: msg.payload.hum,
|
|
234
|
+
tags: {
|
|
235
|
+
location: location
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
return msg;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Example 4: Using Line Protocol
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
// Function node - direct line protocol
|
|
245
|
+
const location = "warehouse";
|
|
246
|
+
const temp = 18.5;
|
|
247
|
+
const humidity = 72;
|
|
248
|
+
|
|
249
|
+
msg.payload = `climate,location=${location} temperature=${temp},humidity=${humidity}`;
|
|
250
|
+
return msg;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Example 5: Multiple Databases
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
// Write to different databases based on data type
|
|
257
|
+
if (msg.payload.type === "critical") {
|
|
258
|
+
msg.database = "critical-events";
|
|
259
|
+
} else {
|
|
260
|
+
msg.database = "general-logs";
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
msg.measurement = "events";
|
|
264
|
+
msg.payload = {
|
|
265
|
+
severity: msg.payload.severity,
|
|
266
|
+
message: msg.payload.msg,
|
|
267
|
+
tags: {
|
|
268
|
+
type: msg.payload.type
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return msg;
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Sample Flow
|
|
275
|
+
|
|
276
|
+
Import this flow into Node-RED to get started:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
[
|
|
280
|
+
{
|
|
281
|
+
"id": "influxdb3-config-node",
|
|
282
|
+
"type": "influxdb3-config",
|
|
283
|
+
"name": "My InfluxDB v3",
|
|
284
|
+
"host": "https://us-east-1-1.aws.cloud2.influxdata.com",
|
|
285
|
+
"database": "my-database"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"id": "inject-node",
|
|
289
|
+
"type": "inject",
|
|
290
|
+
"name": "Generate Data",
|
|
291
|
+
"props": [{"p": "payload"}],
|
|
292
|
+
"repeat": "5",
|
|
293
|
+
"topic": "",
|
|
294
|
+
"payload": "",
|
|
295
|
+
"payloadType": "date",
|
|
296
|
+
"x": 140,
|
|
297
|
+
"y": 100,
|
|
298
|
+
"wires": [["function-node"]]
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"id": "function-node",
|
|
302
|
+
"type": "function",
|
|
303
|
+
"name": "Format Data",
|
|
304
|
+
"func": "msg.measurement = 'temperature';\nmsg.payload = {\n value: 20 + Math.random() * 10,\n tags: {\n location: 'office'\n }\n};\nreturn msg;",
|
|
305
|
+
"x": 320,
|
|
306
|
+
"y": 100,
|
|
307
|
+
"wires": [["influxdb3-write-node"]]
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"id": "influxdb3-write-node",
|
|
311
|
+
"type": "influxdb3-write",
|
|
312
|
+
"name": "Write to InfluxDB",
|
|
313
|
+
"influxdb": "influxdb3-config-node",
|
|
314
|
+
"measurement": "",
|
|
315
|
+
"database": "",
|
|
316
|
+
"x": 530,
|
|
317
|
+
"y": 100,
|
|
318
|
+
"wires": [["debug-node"]]
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"id": "debug-node",
|
|
322
|
+
"type": "debug",
|
|
323
|
+
"name": "Debug",
|
|
324
|
+
"x": 730,
|
|
325
|
+
"y": 100,
|
|
326
|
+
"wires": []
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Configuration with Environment Variables
|
|
332
|
+
|
|
333
|
+
You can use environment variables in the configuration node:
|
|
334
|
+
|
|
335
|
+
- `INFLUX_HOST` - InfluxDB v3 host URL
|
|
336
|
+
- `INFLUX_TOKEN` - Authentication token
|
|
337
|
+
- `INFLUX_DATABASE` - Default database name
|
|
338
|
+
|
|
339
|
+
Simply reference them in the Node-RED UI using `${INFLUX_HOST}` syntax (if using Node-RED environment variable substitution).
|
|
340
|
+
|
|
341
|
+
## Troubleshooting
|
|
342
|
+
|
|
343
|
+
### Connection Issues
|
|
344
|
+
|
|
345
|
+
- Verify your host URL is correct and includes `https://`
|
|
346
|
+
- Check that your token has write permissions for the database
|
|
347
|
+
- Ensure the database name exists in your InfluxDB v3 instance
|
|
348
|
+
|
|
349
|
+
### TLS / Custom Certificates
|
|
350
|
+
|
|
351
|
+
If you are connecting to a local InfluxDB v3 instance with a custom certificate:
|
|
352
|
+
|
|
353
|
+
- Set **CA Cert Path** in the config node to the PEM file containing your root CA. This sets `NODE_EXTRA_CA_CERTS` for the Node-RED process.
|
|
354
|
+
- As a last resort, disable **Verify TLS** to set `NODE_TLS_REJECT_UNAUTHORIZED=0` (this disables TLS verification globally for the process).
|
|
355
|
+
|
|
356
|
+
### Data Not Appearing
|
|
357
|
+
|
|
358
|
+
- Check the node status - it should show "written" briefly after successful writes
|
|
359
|
+
- Verify at least one field is provided (InfluxDB requires at least one field)
|
|
360
|
+
- Check that field values are not null or undefined
|
|
361
|
+
|
|
362
|
+
### Error Messages
|
|
363
|
+
|
|
364
|
+
The node will display error status and log details to the Node-RED debug panel:
|
|
365
|
+
- **"no config"** - The InfluxDB v3 config node is not selected
|
|
366
|
+
- **"error"** - Check the debug panel for details
|
|
367
|
+
|
|
368
|
+
## Requirements
|
|
369
|
+
|
|
370
|
+
- Node-RED v2.0.0 or higher
|
|
371
|
+
- InfluxDB v3 instance (Cloud or Edge)
|
|
372
|
+
|
|
373
|
+
## License
|
|
374
|
+
|
|
375
|
+
MIT
|
|
376
|
+
|
|
377
|
+
## Links
|
|
378
|
+
|
|
379
|
+
- [InfluxDB v3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)
|
|
380
|
+
- [InfluxDB v3 Documentation](https://docs.influxdata.com/influxdb/v3/)
|
|
381
|
+
- [Node-RED](https://nodered.org/)
|
|
382
|
+
|
|
383
|
+
## Contributing
|
|
384
|
+
|
|
385
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
386
|
+
|