Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Josh Proehl
Weatherflow_Tempest
Commits
02639796
Commit
02639796
authored
Feb 25, 2021
by
Josh Proehl
Browse files
Doc updates
parent
906d24d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
02639796
...
...
@@ -36,6 +36,36 @@ If none is defined it will start a pubsub named :weatherflow_tempest and output
## Usage
You can get the latest data heard from the station via
`WeatherflowTempest.get_latest`
, which will return a map
containing the last received message of each message type.
To subscribe to all events use the convenience function
`WeatherflowTempest.PubSub.subscribe_udp_events()`
,
and then handle all incoming events with something like:
```
elixir
def
handle_info
(%{
topic:
"weatherflow:udp"
,
event:
event_type
,
payload:
payload
}
=
msg
,
socket
)
do
Logger
.
debug
(
"Got event type
#{
msg
.
event
}
"
)
{
:noreply
,
socket
}
end
```
The broadcasts use
`%Phoenix.Socket.Broadcast{}`
structs, the topic is set as "weatherflow:udp", the event represents
the type of event, and the payload is the flattened and transformed payload from the Weatherflow station.
The events returned are fullname-expanded versions of the type codes of the WeatherFlow API:
-
:event_precipitation
-
:event_strike
-
:rapid_wind
-
:observation_air
-
:observation_sky
-
:observation_tempest
-
:device_status
-
:hub_status
The payload for each event is transformed from the UDP API format by
`WeatherFlowTempest.Client`
, but in short it will
be a map containing all data returned by the API as key/value pairs.
It is worth noting that the type key is stripped from the results (due to us changing the event names to be clearer),
so if you are passing the messages on further you will need to keep the association between object and type manually.
## License
...
...
lib/weatherflow_tempest/client.ex
View file @
02639796
...
...
@@ -2,7 +2,9 @@ defmodule WeatherflowTempest.Client do
@moduledoc
"""
Listens for packets from Weatherflow devices on the LAN and stores their latest state/update in its own state.
Outputs events via Phoenix PubSub on channel name :weatherflow_tempest
Outputs events via `WeatherflowTempest.PubSub.udp_event_broadcast/2`.
Events containing observations are flattened into a single observation with all observation keys as top-level keys.
"""
use
GenServer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment