influxdata / influxdata/iot-api-js

Update app to use InfluxDB 3 Core

Open
#38 0 comments 0 reactions 1 assignee View on GitHub

@jstirnaman is already working on this.

Since Feb 10, 2026.

Dominant language
JavaScript
Stars
12
Forks
5
Avg merge
2d 16h
Merged PRs (30d)
2

Description

Use InfluxDB 3 Core


Overview


Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the @influxdata/influxdb3-client JavaScript client library.




Phase 1: Core Migration ✅


Environment Changes

Variable | New Value | Replaces
-- | -- | --
INFLUX_HOST | http://localhost:8181 | INFLUX_URL
INFLUX_DATABASE | iot_center | INFLUX_BUCKET
INFLUX_DATABASE_AUTH | iot_center_devices | INFLUX_BUCKET_AUTH
INFLUX_TOKEN | Admin token | Same
~~INFLUX_ORG~~ | Removed | Not used in InfluxDB 3



References





Related



  • PR #18: Initial migration implementation

  • Branch: claude/influxdb3-migration-v3-pMqwy

## Use InfluxDB 3 Core

### Overview

Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the `@influxdata/influxdb3-client` JavaScript client library.

---

## Phase 1: Core Migration ✅

### Environment Changes
| Variable | New Value | Replaces |
|----------|-----------|----------|
| `INFLUX_HOST` | `http://localhost:8181` | `INFLUX_URL` |
| `INFLUX_DATABASE` | `iot_center` | `INFLUX_BUCKET` |
| `INFLUX_DATABASE_AUTH` | `iot_center_devices` | `INFLUX_BUCKET_AUTH` |
| `INFLUX_TOKEN` | Admin token | Same |
| ~~`INFLUX_ORG`~~ | Removed | Not used in InfluxDB 3 |

### Client Library Migration
- Replace `@influxdata/influxdb-client` with `@influxdata/influxdb3-client` v2.0.0
- Use `InfluxDBClient` class with `{ host, token }` configuration
- Use `Point` class for line protocol construction
- Use `client.query(sql, database)` for SQL queries
- Use `client.write(data, database)` for writes

### Query Language Migration
- Convert all Flux queries to SQL
- InfluxDB 3 Core supports SQL queries only (no Flux)
- Query limit: Last 72 hours of data (Core limitation)

### Authentication Changes
- InfluxDB 3 Core does not have the Authorizations API
- Implement application-level device tokens stored in `iot_center_devices` database
- Generate tokens using `crypto.randomBytes(32).toString('hex')`
- Store device credentials as line protocol with `deviceauth` measurement

### API Endpoints Migrated
- [x] `GET /api/devices` - List all devices (SQL query)
- [x] `GET /api/devices/:deviceId` - Get single device (SQL query with parameter)
- [x] `POST /api/devices/create` - Create device with application token
- [x] `GET /api/measurements` - Query telemetry data (SQL query)

---

## Phase 2: Core Enhancements

### Last Value Cache (LVC)
Sub-10ms query performance for latest device readings.

```bash
influxdb3 create last_cache \
--database iot_center \
--table environment \
--key-columns deviceId \
--value-columns Temperature,Humidity,Pressure,CO2
```

**Use case**: Real-time dashboard showing current sensor values for all devices.

### Distinct Value Cache (DVC)
Fast metadata lookups without full table scans.

```bash
influxdb3 create distinct_cache \
--database iot_center \
--table environment \
--columns deviceId,deviceType,location
```

**Use case**: Populate device filter dropdowns, list available locations.

### Processing Engine
Python plugins for data processing triggered by WAL writes, schedules, or HTTP requests.

**Example: Temperature Alert Plugin**
```python
# temperature_alert.py
def process_writes(influxdb3_local, table_batches, args):
for table_batch in table_batches:
if table_batch["table_name"] == "environment":
for row in table_batch["rows"]:
if row.get("Temperature", 0) > args.get("threshold", 30):
influxdb3_local.write(
f'alerts,deviceId={row["deviceId"]},type=temperature '
f'value={row["Temperature"]},message="High temperature"'
)
```

**Use cases**:
- Temperature threshold alerts (WAL trigger)
- Daily device health summary (scheduled)
- On-demand data aggregation (HTTP request)

---

## Technical Notes

### InfluxDB 3 Core Limitations
| Limitation | Description |
|------------|-------------|
| Query window | Last 72 hours only |
| Authentication | No resource tokens (use application-level auth) |
| Availability | Single node only |
| Processing Engine | Python plugins only |

### Data Model Changes
| InfluxDB 3 | InfluxDB 2.x |
|------------|--------------|
| Database | Bucket |
| Table | Measurement |
| Tags | Tags |
| Fields | Fields |

---

## References

- [[InfluxDB 3 Core Documentation](https://docs.influxdata.com/influxdb3/core/)](https://docs.influxdata.com/influxdb3/core/)
- [[InfluxDB 3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)](https://github.com/InfluxCommunity/influxdb3-js)
- [[Query data with SQL](https://docs.influxdata.com/influxdb3/core/query-data/sql/)](https://docs.influxdata.com/influxdb3/core/query-data/sql/)
- [[Last Value Cache](https://docs.influxdata.com/influxdb3/core/query-data/last-value-cache/)](https://docs.influxdata.com/influxdb3/core/query-data/last-value-cache/)
- [[Processing Engine](https://docs.influxdata.com/influxdb3/core/process-data/process-engine/)](https://docs.influxdata.com/influxdb3/core/process-data/process-engine/)

---

## Related

- PR #18: Initial migration implementation
- Branch: `claude/influxdb3-migration-v3-pMqwy`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.