Published
Edited
Dec 11, 2020
Insert cell
md`# Protenga BME680 vs SCD30 Sensors`
Insert cell
url = "https://mqtt.boomgrowfarms.com/protenga/esp32-sensor/_design/sensor/_view/all-sensor?skip=5000"
Insert cell
md `Disable CORS in nginx with

add_header 'Access-Control-Allow-Origin' '*';

add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
`
Insert cell
d3 = require("d3@5")
Insert cell
md `### Load all the json
- key : sensor name
- value: { timestamp, timestamp2, sensor data }

### co2Format is key value pairs for charts

- name : timestamp
- value : sensor data
`
Insert cell
sensor = await d3.json(url)
Insert cell
//bme2 = bme.splice(0,500)
Insert cell
bme_rh = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.rh_bme
})
)
Insert cell
bme_te = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.te_bme
})
)
Insert cell
bme_co2 = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.co2_bme
})
)
Insert cell
scd_rh = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.rh_scd
})
)
Insert cell
scd_te = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.te_scd
})
)
Insert cell
scd_co2 = sensor.rows
.map(d => (
{
name: d.value.ts,
value: d.value.co2_scd
})
)
Insert cell
md ` ## RH Charts`
Insert cell
import {chart as rh_chart} with { rh as data } from '@d3/bar-chart'
Insert cell
md ` ## Temp Charts`
Insert cell
import {chart as te_chart} with { te as data } from '@d3/bar-chart'
Insert cell
md `## Format for multiple series

- series is data points in multiple arrays
- dates is timestamps in an array
`
Insert cell
co2_data = ({series : [
{name : "BME680", values:bme_co2.map(item => item.value)},
{name : "SCD30", values:scd_co2.map(item => item.value)},
],
dates: bme_co2.map(item => item.name*1000 )})
Insert cell
combo_data = ({series : [
{name : "BME680 TE", values:bme_te.map(item => item.value)},
{name : "SCD30 TE", values:scd_te.map(item => item.value)},
{name : "BME680 RH", values:bme_rh.map(item => item.value)},
{name : "SCD30 RH", values:scd_rh.map(item => item.value)},
],
dates: bme_te.map(item => item.name*1000 )})
Insert cell
md `### %Q in d3.timeParse() is epoch data`
Insert cell
parser = d3.timeParse("%Q")
Insert cell
start = bme_te.map(d => parser(d.name*1000) );
Insert cell
//allTS = teFormat.map(d => parser(d.name*1000) );
Insert cell
import {chart as co2_charts} with { co2_data as data } from '@stanleyseow/multi-line-chart'
Insert cell
import {chart as te_charts} with { combo_data as data } from '@stanleyseow/multi-line-chart'
Insert cell
co2chart = co2_charts

Insert cell
te_charts
Insert cell
md`---
## Appendix
`
Insert cell
md `## Requires D3`
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more