Comments (2)
Hi. Can you send me your server file (ruuvi.py).
File "ruuvi.py", line 50, in update_data
allData[key][0] = value
TypeError: tuple indices must be integers or slices, not str
It seems that it uses tuple instead of dictionary for some reason. Couldn't find same line from the default example implementation (https://github.com/ttu/ruuvitag-sensor/blob/master/examples/http_server.py).
from ruuvitag-sensor.
Huomenta (o;
Well it is actually this file just with modified MAC addresses:
"""
Simple http server, that returns data in json.
Executes get data for sensors in the background.
Endpoints:
http://0.0.0.0:5000/data
http://0.0.0.0:5000/data/<mac>
Requires:
Flask - pip install flask
"""
from datetime import datetime
import json
from multiprocessing import Manager
from concurrent.futures import ProcessPoolExecutor
from flask import Flask, abort
from ruuvitag_sensor.ruuvi import RuuviTagSensor
app = Flask(__name__)
m = Manager()
q = m.Queue()
allData = {}
tags = {
'EF:DE:E1:49:3C:9B': 'office',
'E9:39:41:56:D6:2D': 'livingroom'
}
def run_get_data_background(macs, queue):
"""
Background process from RuuviTag Sensors
"""
def callback(data):
data[1]['time'] = str(datetime.now())
queue.put(data)
RuuviTagSensor.get_datas(callback, macs)
def update_data():
"""
Update data sent by background process to global allData
"""
global allData
while not q.empty():
allData = q.get()
for key, value in tags.items():
if key in allData:
allData[key]['name'] = value
@app.route('/data')
def get_all_data():
update_data()
return json.dumps(allData)
@app.route('/data/<mac>')
def get_data(mac):
update_data()
if mac not in allData:
abort(404)
return json.dumps(allData[mac])
if __name__ == '__main__':
# Start background process
executor = ProcessPoolExecutor(1)
executor.submit(run_get_data_background, list(tags.keys()), q)
# Strt Flask application
app.run(host='0.0.0.0', port=5000)
Just redownloaded it and changed the MAC addresses....still the same error:
from ruuvitag-sensor.
Related Issues (20)
- Ruuvitags and InfluxDB 2 HOT 6
- README.md has broken link to Setup guide HOT 1
- Updated install instructions ffor Rasperry Pi HOT 1
- Latest firmware using data format 2 HOT 1
- Can't get device info: No such device HOT 1
- Stuck after "Invalid advertisement data" error. HOT 5
- High CPU usage with Bleson backend HOT 1
- "Cannot read %d bytes, data too short" error causes ruuvitag-sensors to stop working HOT 1
- Cross-platform BLE communicaton with Bleak
- Changing the spelling of datas to data HOT 9
- find_ruuvitags_async payload contains non-parsed data HOT 1
- ruuvi_rx should support Bleak-adapter HOT 3
- Add tests for find_ruuvitags_async HOT 1
- Use typing in examples HOT 3
- BleCommunicationBleak doesn't work with asyncio.run() HOT 3
- Docs request: Pull Request Templates HOT 1
- Data Format Mismatch HOT 2
- Get sensor data with callback stopped working after new firmware HOT 3
- Bleak Async call failing ... no attribute HOT 1
- Development install fails HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruuvitag-sensor.