Platform
Resources
Pricing
Sign in
Get started
Tom Larkworthy
Tech Lead at Taktile. Formerly Firebase, Google
Workspace
Fork
Published
Building a SMART FARM
By
Tom Larkworthy
Edited
Jul 27, 2022
2 forks
7 stars
1
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
firebaseConfig
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
db
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sensorName
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sensorTemperature
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
uploadSensor
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
querySensorName
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
result
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
liveViewRaw
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
liveView
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML