Published
Edited
Jul 27, 2022
2 forks
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.lineY(liveView, { x: (d) => new Date(d.time), y: (d) => d.temp }),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.button("upload data", {
reduce: () => {
uploadSensor();
}
})
Insert cell
function uploadSensor() {
const time = Date.now();
db.ref(`current/sensors/${sensorName}`).set({
location: "-76.5 4.7",
time,
temp: sensorTemperature,
battery: 0.5
});
db.ref(`history/sensors/${sensorName}/${time}`).set({
location: "-76.5 4.7",
time,
temp: sensorTemperature,
battery: 0.5
});
}
Insert cell
Insert cell
Insert cell
Insert cell
result = (
await db.ref(`history/sensors/${querySensorName}`).once("value")
).toJSON()
Insert cell
Insert cell
liveViewRaw = Generators.observe((notify) => {
db.ref(`history/sensors/${querySensorName}`)
.limitToLast(6) // reduce data returned
.on("value", (snapshot) => {
const data = snapshot.val();
notify(data);
});
})
Insert cell
liveView = Object.entries(liveViewRaw).map(([k, v]) => v)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more