node-red-contrib-influxdb3 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -1,377 +1,377 @@
1
- # node-red-contrib-influxdb3
2
-
3
- [![npm version](https://badge.fury.io/js/node-red-contrib-influxdb3.svg)](https://www.npmjs.com/package/node-red-contrib-influxdb3)
4
- [![npm downloads](https://img.shields.io/npm/dm/node-red-contrib-influxdb3.svg)](https://www.npmjs.com/package/node-red-contrib-influxdb3)
5
- [![Node-RED](https://img.shields.io/badge/Node--RED-contrib-red.svg)](https://flows.nodered.org/node/node-red-contrib-influxdb3)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
-
56
- ### InfluxDB v3 Write Node
57
-
58
- Writes data points to InfluxDB v3.
59
-
60
- **Configuration:**
61
- - **Connection**: Select an InfluxDB v3 config node
62
- - **Name**: Optional node name
63
- - **Measurement**: Default measurement name (can be overridden by `msg.measurement`)
64
- - **Database**: Optional database override (uses connection default if not set)
65
-
66
- ## Usage
67
-
68
- ### Input Message Formats
69
-
70
- The write node accepts data in multiple formats:
71
-
72
- #### 1. Line Protocol String
73
-
74
- Send data as a string in InfluxDB line protocol format:
75
-
76
- ```javascript
77
- msg.payload = "temperature,location=room1 value=21.5";
78
- return msg;
79
- ```
80
-
81
- #### 2. Object with Fields and Tags
82
-
83
- Send an object with explicit `fields` and `tags` properties:
84
-
85
- ```javascript
86
- msg.measurement = "temperature";
87
- msg.payload = {
88
- fields: {
89
- value: 21.5,
90
- humidity: 65
91
- },
92
- tags: {
93
- location: "room1",
94
- sensor: "dht22"
95
- },
96
- timestamp: Date.now() // optional
97
- };
98
- return msg;
99
- ```
100
-
101
- #### 3. Simplified Object Format
102
-
103
- Send an object where all properties (except 'tags' and 'timestamp') are treated as fields:
104
-
105
- ```javascript
106
- msg.measurement = "environment";
107
- msg.payload = {
108
- temperature: 21.5,
109
- humidity: 65,
110
- pressure: 1013.25,
111
- tags: {
112
- room: "bedroom",
113
- floor: "2"
114
- }
115
- };
116
- return msg;
117
- ```
118
-
119
- ### Data Types
120
-
121
- **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.
122
-
123
- When using object format, the node handles data types as follows:
124
- - **Numbers**: Written as **float fields** by default
125
- - **Integers**: Must be explicitly marked (see below)
126
- - **Booleans**: Written as boolean fields
127
- - **Strings**: Written as string fields
128
- - **Tags**: Always converted to strings
129
-
130
- #### Writing Integer Fields
131
-
132
- To write integers explicitly, use one of these methods:
133
-
134
- **Method 1: Using the `integers` array**
135
- ```javascript
136
- msg.payload = {
137
- fields: {
138
- temperature: 21.5, // float
139
- count: 42, // will be float by default
140
- total: 100 // will be float by default
141
- },
142
- integers: ['count', 'total'] // mark these as integers
143
- };
144
- ```
145
-
146
- **Method 2: Using the `i` suffix**
147
- ```javascript
148
- msg.payload = {
149
- fields: {
150
- temperature: 21.5, // float
151
- count: "42i", // integer (note the string with 'i' suffix)
152
- total: "100i" // integer
153
- }
154
- };
155
- ```
156
-
157
- **Example with both floats and integers:**
158
- ```javascript
159
- msg.measurement = "sensor_data";
160
- msg.payload = {
161
- temperature: 21.5, // float
162
- humidity: 65.0, // float (even though it looks like an integer)
163
- event_count: "50i", // integer
164
- tags: {
165
- location: "room1"
166
- }
167
- };
168
- ```
169
-
170
- ### Message Properties
171
-
172
- The following message properties can be used to override node configuration:
173
-
174
- - `msg.measurement` - Override the measurement name
175
- - `msg.database` - Override the database name
176
- - `msg.timestamp` - Set the timestamp for the data point (Date object or milliseconds)
177
- - `msg.payload.integers` - Array of field names to write as integers (e.g., `['count', 'total']`)
178
-
179
- ## Examples
180
-
181
- ### Example 1: Temperature Sensor
182
-
183
- ```javascript
184
- // Function node
185
- msg.measurement = "temperature";
186
- msg.payload = {
187
- value: 21.5,
188
- tags: {
189
- location: "living_room",
190
- sensor_id: "temp_001"
191
- }
192
- };
193
- return msg;
194
- ```
195
-
196
- ### Example 2: Multi-Sensor Data
197
-
198
- ```javascript
199
- // Function node
200
- msg.measurement = "environment";
201
- msg.payload = {
202
- fields: {
203
- temperature: 22.3,
204
- humidity: 58,
205
- co2: 412,
206
- light: 850
207
- },
208
- tags: {
209
- room: "office",
210
- floor: "3",
211
- building: "A"
212
- }
213
- };
214
- return msg;
215
- ```
216
-
217
- ### Example 3: MQTT to InfluxDB
218
-
219
- ```
220
- [MQTT In] --> [JSON Parse] --> [Function] --> [InfluxDB v3 Write]
221
- ```
222
-
223
- Function node:
224
- ```javascript
225
- // Parse MQTT topic for location
226
- const location = msg.topic.split('/')[1];
227
-
228
- msg.measurement = "sensor_data";
229
- msg.payload = {
230
- temperature: msg.payload.temp,
231
- humidity: msg.payload.hum,
232
- tags: {
233
- location: location
234
- }
235
- };
236
- return msg;
237
- ```
238
-
239
- ### Example 4: Using Line Protocol
240
-
241
- ```javascript
242
- // Function node - direct line protocol
243
- const location = "warehouse";
244
- const temp = 18.5;
245
- const humidity = 72;
246
-
247
- msg.payload = `climate,location=${location} temperature=${temp},humidity=${humidity}`;
248
- return msg;
249
- ```
250
-
251
- ### Example 5: Multiple Databases
252
-
253
- ```javascript
254
- // Write to different databases based on data type
255
- if (msg.payload.type === "critical") {
256
- msg.database = "critical-events";
257
- } else {
258
- msg.database = "general-logs";
259
- }
260
-
261
- msg.measurement = "events";
262
- msg.payload = {
263
- severity: msg.payload.severity,
264
- message: msg.payload.msg,
265
- tags: {
266
- type: msg.payload.type
267
- }
268
- };
269
- return msg;
270
- ```
271
-
272
- ## Sample Flow
273
-
274
- Import this flow into Node-RED to get started:
275
-
276
- ```json
277
- [
278
- {
279
- "id": "influxdb3-config-node",
280
- "type": "influxdb3-config",
281
- "name": "My InfluxDB v3",
282
- "host": "https://us-east-1-1.aws.cloud2.influxdata.com",
283
- "database": "my-database"
284
- },
285
- {
286
- "id": "inject-node",
287
- "type": "inject",
288
- "name": "Generate Data",
289
- "props": [{"p": "payload"}],
290
- "repeat": "5",
291
- "topic": "",
292
- "payload": "",
293
- "payloadType": "date",
294
- "x": 140,
295
- "y": 100,
296
- "wires": [["function-node"]]
297
- },
298
- {
299
- "id": "function-node",
300
- "type": "function",
301
- "name": "Format Data",
302
- "func": "msg.measurement = 'temperature';\nmsg.payload = {\n value: 20 + Math.random() * 10,\n tags: {\n location: 'office'\n }\n};\nreturn msg;",
303
- "x": 320,
304
- "y": 100,
305
- "wires": [["influxdb3-write-node"]]
306
- },
307
- {
308
- "id": "influxdb3-write-node",
309
- "type": "influxdb3-write",
310
- "name": "Write to InfluxDB",
311
- "influxdb": "influxdb3-config-node",
312
- "measurement": "",
313
- "database": "",
314
- "x": 530,
315
- "y": 100,
316
- "wires": [["debug-node"]]
317
- },
318
- {
319
- "id": "debug-node",
320
- "type": "debug",
321
- "name": "Debug",
322
- "x": 730,
323
- "y": 100,
324
- "wires": []
325
- }
326
- ]
327
- ```
328
-
329
- ## Configuration with Environment Variables
330
-
331
- You can use environment variables in the configuration node:
332
-
333
- - `INFLUX_HOST` - InfluxDB v3 host URL
334
- - `INFLUX_TOKEN` - Authentication token
335
- - `INFLUX_DATABASE` - Default database name
336
-
337
- Simply reference them in the Node-RED UI using `${INFLUX_HOST}` syntax (if using Node-RED environment variable substitution).
338
-
339
- ## Troubleshooting
340
-
341
- ### Connection Issues
342
-
343
- - Verify your host URL is correct and includes `https://`
344
- - Check that your token has write permissions for the database
345
- - Ensure the database name exists in your InfluxDB v3 instance
346
-
347
- ### Data Not Appearing
348
-
349
- - Check the node status - it should show "written" briefly after successful writes
350
- - Verify at least one field is provided (InfluxDB requires at least one field)
351
- - Check that field values are not null or undefined
352
-
353
- ### Error Messages
354
-
355
- The node will display error status and log details to the Node-RED debug panel:
356
- - **"no config"** - The InfluxDB v3 config node is not selected
357
- - **"error"** - Check the debug panel for details
358
-
359
- ## Requirements
360
-
361
- - Node-RED v2.0.0 or higher
362
- - InfluxDB v3 instance (Cloud or Edge)
363
-
364
- ## License
365
-
366
- MIT
367
-
368
- ## Links
369
-
370
- - [InfluxDB v3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)
371
- - [InfluxDB v3 Documentation](https://docs.influxdata.com/influxdb/v3/)
372
- - [Node-RED](https://nodered.org/)
373
-
374
- ## Contributing
375
-
376
- Contributions are welcome! Please feel free to submit a Pull Request.
377
-
1
+ # node-red-contrib-influxdb3
2
+
3
+ [![npm version](https://badge.fury.io/js/node-red-contrib-influxdb3.svg)](https://www.npmjs.com/package/node-red-contrib-influxdb3)
4
+ [![npm downloads](https://img.shields.io/npm/dm/node-red-contrib-influxdb3.svg)](https://www.npmjs.com/package/node-red-contrib-influxdb3)
5
+ [![Node-RED](https://img.shields.io/badge/Node--RED-contrib-red.svg)](https://flows.nodered.org/node/node-red-contrib-influxdb3)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
+
56
+ ### InfluxDB v3 Write Node
57
+
58
+ Writes data points to InfluxDB v3.
59
+
60
+ **Configuration:**
61
+ - **Connection**: Select an InfluxDB v3 config node
62
+ - **Name**: Optional node name
63
+ - **Measurement**: Default measurement name (can be overridden by `msg.measurement`)
64
+ - **Database**: Optional database override (uses connection default if not set)
65
+
66
+ ## Usage
67
+
68
+ ### Input Message Formats
69
+
70
+ The write node accepts data in multiple formats:
71
+
72
+ #### 1. Line Protocol String
73
+
74
+ Send data as a string in InfluxDB line protocol format:
75
+
76
+ ```javascript
77
+ msg.payload = "temperature,location=room1 value=21.5";
78
+ return msg;
79
+ ```
80
+
81
+ #### 2. Object with Fields and Tags
82
+
83
+ Send an object with explicit `fields` and `tags` properties:
84
+
85
+ ```javascript
86
+ msg.measurement = "temperature";
87
+ msg.payload = {
88
+ fields: {
89
+ value: 21.5,
90
+ humidity: 65
91
+ },
92
+ tags: {
93
+ location: "room1",
94
+ sensor: "dht22"
95
+ },
96
+ timestamp: Date.now() // optional
97
+ };
98
+ return msg;
99
+ ```
100
+
101
+ #### 3. Simplified Object Format
102
+
103
+ Send an object where all properties (except 'tags' and 'timestamp') are treated as fields:
104
+
105
+ ```javascript
106
+ msg.measurement = "environment";
107
+ msg.payload = {
108
+ temperature: 21.5,
109
+ humidity: 65,
110
+ pressure: 1013.25,
111
+ tags: {
112
+ room: "bedroom",
113
+ floor: "2"
114
+ }
115
+ };
116
+ return msg;
117
+ ```
118
+
119
+ ### Data Types
120
+
121
+ **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.
122
+
123
+ When using object format, the node handles data types as follows:
124
+ - **Numbers**: Written as **float fields** by default
125
+ - **Integers**: Must be explicitly marked (see below)
126
+ - **Booleans**: Written as boolean fields
127
+ - **Strings**: Written as string fields
128
+ - **Tags**: Always converted to strings
129
+
130
+ #### Writing Integer Fields
131
+
132
+ To write integers explicitly, use one of these methods:
133
+
134
+ **Method 1: Using the `integers` array**
135
+ ```javascript
136
+ msg.payload = {
137
+ fields: {
138
+ temperature: 21.5, // float
139
+ count: 42, // will be float by default
140
+ total: 100 // will be float by default
141
+ },
142
+ integers: ['count', 'total'] // mark these as integers
143
+ };
144
+ ```
145
+
146
+ **Method 2: Using the `i` suffix**
147
+ ```javascript
148
+ msg.payload = {
149
+ fields: {
150
+ temperature: 21.5, // float
151
+ count: "42i", // integer (note the string with 'i' suffix)
152
+ total: "100i" // integer
153
+ }
154
+ };
155
+ ```
156
+
157
+ **Example with both floats and integers:**
158
+ ```javascript
159
+ msg.measurement = "sensor_data";
160
+ msg.payload = {
161
+ temperature: 21.5, // float
162
+ humidity: 65.0, // float (even though it looks like an integer)
163
+ event_count: "50i", // integer
164
+ tags: {
165
+ location: "room1"
166
+ }
167
+ };
168
+ ```
169
+
170
+ ### Message Properties
171
+
172
+ The following message properties can be used to override node configuration:
173
+
174
+ - `msg.measurement` - Override the measurement name
175
+ - `msg.database` - Override the database name
176
+ - `msg.timestamp` - Set the timestamp for the data point (Date object or milliseconds)
177
+ - `msg.payload.integers` - Array of field names to write as integers (e.g., `['count', 'total']`)
178
+
179
+ ## Examples
180
+
181
+ ### Example 1: Temperature Sensor
182
+
183
+ ```javascript
184
+ // Function node
185
+ msg.measurement = "temperature";
186
+ msg.payload = {
187
+ value: 21.5,
188
+ tags: {
189
+ location: "living_room",
190
+ sensor_id: "temp_001"
191
+ }
192
+ };
193
+ return msg;
194
+ ```
195
+
196
+ ### Example 2: Multi-Sensor Data
197
+
198
+ ```javascript
199
+ // Function node
200
+ msg.measurement = "environment";
201
+ msg.payload = {
202
+ fields: {
203
+ temperature: 22.3,
204
+ humidity: 58,
205
+ co2: 412,
206
+ light: 850
207
+ },
208
+ tags: {
209
+ room: "office",
210
+ floor: "3",
211
+ building: "A"
212
+ }
213
+ };
214
+ return msg;
215
+ ```
216
+
217
+ ### Example 3: MQTT to InfluxDB
218
+
219
+ ```
220
+ [MQTT In] --> [JSON Parse] --> [Function] --> [InfluxDB v3 Write]
221
+ ```
222
+
223
+ Function node:
224
+ ```javascript
225
+ // Parse MQTT topic for location
226
+ const location = msg.topic.split('/')[1];
227
+
228
+ msg.measurement = "sensor_data";
229
+ msg.payload = {
230
+ temperature: msg.payload.temp,
231
+ humidity: msg.payload.hum,
232
+ tags: {
233
+ location: location
234
+ }
235
+ };
236
+ return msg;
237
+ ```
238
+
239
+ ### Example 4: Using Line Protocol
240
+
241
+ ```javascript
242
+ // Function node - direct line protocol
243
+ const location = "warehouse";
244
+ const temp = 18.5;
245
+ const humidity = 72;
246
+
247
+ msg.payload = `climate,location=${location} temperature=${temp},humidity=${humidity}`;
248
+ return msg;
249
+ ```
250
+
251
+ ### Example 5: Multiple Databases
252
+
253
+ ```javascript
254
+ // Write to different databases based on data type
255
+ if (msg.payload.type === "critical") {
256
+ msg.database = "critical-events";
257
+ } else {
258
+ msg.database = "general-logs";
259
+ }
260
+
261
+ msg.measurement = "events";
262
+ msg.payload = {
263
+ severity: msg.payload.severity,
264
+ message: msg.payload.msg,
265
+ tags: {
266
+ type: msg.payload.type
267
+ }
268
+ };
269
+ return msg;
270
+ ```
271
+
272
+ ## Sample Flow
273
+
274
+ Import this flow into Node-RED to get started:
275
+
276
+ ```json
277
+ [
278
+ {
279
+ "id": "influxdb3-config-node",
280
+ "type": "influxdb3-config",
281
+ "name": "My InfluxDB v3",
282
+ "host": "https://us-east-1-1.aws.cloud2.influxdata.com",
283
+ "database": "my-database"
284
+ },
285
+ {
286
+ "id": "inject-node",
287
+ "type": "inject",
288
+ "name": "Generate Data",
289
+ "props": [{"p": "payload"}],
290
+ "repeat": "5",
291
+ "topic": "",
292
+ "payload": "",
293
+ "payloadType": "date",
294
+ "x": 140,
295
+ "y": 100,
296
+ "wires": [["function-node"]]
297
+ },
298
+ {
299
+ "id": "function-node",
300
+ "type": "function",
301
+ "name": "Format Data",
302
+ "func": "msg.measurement = 'temperature';\nmsg.payload = {\n value: 20 + Math.random() * 10,\n tags: {\n location: 'office'\n }\n};\nreturn msg;",
303
+ "x": 320,
304
+ "y": 100,
305
+ "wires": [["influxdb3-write-node"]]
306
+ },
307
+ {
308
+ "id": "influxdb3-write-node",
309
+ "type": "influxdb3-write",
310
+ "name": "Write to InfluxDB",
311
+ "influxdb": "influxdb3-config-node",
312
+ "measurement": "",
313
+ "database": "",
314
+ "x": 530,
315
+ "y": 100,
316
+ "wires": [["debug-node"]]
317
+ },
318
+ {
319
+ "id": "debug-node",
320
+ "type": "debug",
321
+ "name": "Debug",
322
+ "x": 730,
323
+ "y": 100,
324
+ "wires": []
325
+ }
326
+ ]
327
+ ```
328
+
329
+ ## Configuration with Environment Variables
330
+
331
+ You can use environment variables in the configuration node:
332
+
333
+ - `INFLUX_HOST` - InfluxDB v3 host URL
334
+ - `INFLUX_TOKEN` - Authentication token
335
+ - `INFLUX_DATABASE` - Default database name
336
+
337
+ Simply reference them in the Node-RED UI using `${INFLUX_HOST}` syntax (if using Node-RED environment variable substitution).
338
+
339
+ ## Troubleshooting
340
+
341
+ ### Connection Issues
342
+
343
+ - Verify your host URL is correct and includes `https://`
344
+ - Check that your token has write permissions for the database
345
+ - Ensure the database name exists in your InfluxDB v3 instance
346
+
347
+ ### Data Not Appearing
348
+
349
+ - Check the node status - it should show "written" briefly after successful writes
350
+ - Verify at least one field is provided (InfluxDB requires at least one field)
351
+ - Check that field values are not null or undefined
352
+
353
+ ### Error Messages
354
+
355
+ The node will display error status and log details to the Node-RED debug panel:
356
+ - **"no config"** - The InfluxDB v3 config node is not selected
357
+ - **"error"** - Check the debug panel for details
358
+
359
+ ## Requirements
360
+
361
+ - Node-RED v2.0.0 or higher
362
+ - InfluxDB v3 instance (Cloud or Edge)
363
+
364
+ ## License
365
+
366
+ MIT
367
+
368
+ ## Links
369
+
370
+ - [InfluxDB v3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)
371
+ - [InfluxDB v3 Documentation](https://docs.influxdata.com/influxdb/v3/)
372
+ - [Node-RED](https://nodered.org/)
373
+
374
+ ## Contributing
375
+
376
+ Contributions are welcome! Please feel free to submit a Pull Request.
377
+