Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
run for all sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
taivop committed Sep 15, 2021
1 parent 48a56b0 commit 65383ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions poll.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import logging
import os

import websockets
Expand All @@ -11,6 +12,11 @@

load_dotenv() # Take environment variables from .env. See .env.example.

# Setup logging
logging.basicConfig()
logger = logging.getLogger("poll")
logger.setLevel(logging.INFO)

INFLUXDB_TOKEN = os.environ["INFLUXDB_TOKEN"]
INFLUXDB_URL = os.environ["INFLUXDB_URL"]
INFLUXDB_ORG = os.environ["INFLUXDB_ORG"]
Expand All @@ -26,15 +32,16 @@

async def poll_once(host):
uri = f"ws://{host['address']}"
print(uri)
async with websockets.connect(uri) as websocket:
print(f"connected to {uri}")
logger.info("Connecting to '%s' at '%s'", host["name"], uri)

async with websockets.connect(uri) as websocket:
# Ask for all sensor values
await websocket.send("J1.15S\r")
message = await websocket.recv()
sensor_data = parse_sensor_data(message.decode("utf-8"))
logger.debug("'%s' readings: %s", host["name"], sensor_data)

# Assemble message for InfluxDB
sequence = []
for field in sensor_data:
sequence.append(f"{field},host={uri} {field}={sensor_data[field]}")
Expand Down
6 changes: 3 additions & 3 deletions reactors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{
"id":0,
"address":"192.168.1.241",
"name":"blue"
"name":"red"
},
{
"id":1,
"address":"192.168.1.242",
"name":"red"
"name":"purple"
},
{
"id":2,
"address":"192.168.1.243",
"name":"purple"
"name":"blue"
}
]
}

0 comments on commit 65383ec

Please sign in to comment.