Network Overview for Weather and Video Delivery
What weather station hardware does SDRC use?
- Ambient Weather WS-2902 WiFi Smart Weather Station (Amazon link)
- Mounted on the south east side of the Coggeshall Rowing Center at about 8 feet above the roof and parapet
- The WS-2902 communicates to a base station via 900 Mhz to transmit current weather data
- The base station is connected to the SDRC WiFi so that it can send data to the Internet
- Data is presented on Ambient Weather's San Diego Rowing Club dashboard
How is the data published to other web sites?
- SDRC publishes it's data to Weather Underground as it is a popular site for others to subscribe and view local weather data. Here are the instructions for publishing data to Weather Underground from your Ambient Weather station.
How do you get the paragraph of text that describes the weather conditions?
-
- Our website is built on WordPress and we use the Weather Station plugin.
- Under Weather Station Setting you can add a connection to the Ambient Weather Network. The plugin will gather the data and make it available for publication.
- Once Weather Station is installed and configured, you can add HTML similar to the following which WordPress will parse. See the documentation for the Weather Station plugin for exact details.
[widget="temp"] On [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m0:c0:00:00:00:02' measure_type='last_refresh' element='measure_timestamp' format='local-date' fx='none' color='#000000' speed='2000'] at [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m0:c0:00:00:00:02' measure_type='last_refresh' element='measure_timestamp' format='local-time' fx='none' color='#000000' speed='2000'] the temperature was [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m1:c0:00:00:00:02' measure_type='temperature' element='measure_value' format='computed-unit' fx='none' color='#000000' speed='2000'] with the wind at [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m2:c0:00:00:00:02' measure_type='windstrength' element='measure_value' format='computed-unit' fx='none' color='#000000' speed='2000'] from the [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m2:c0:00:00:00:02' measure_type='windangle' element='measure_value' format='short-text' fx='none' color='#000000' speed='2000']. The humidity level was [live-weather-station-livetextual device_id='f4:cf:a2:8a:9a:7b' module_id='m1:c0:00:00:00:02' measure_type='humidity' element='measure_value' format='computed-unit' fx='none' color='#ffffff' speed='2000'].
How do you publish a live video stream?
The actual implementation may be beyond the scope of this website, so write dano@sandiegorowing.org if you want to explore how this is done beyond what is presented here.
The camera is a standard HIKVISION Outdoor Dome camera. Ours was donated, so we don't have any particular model to recommend. Any camera that can provide an RTSP stream via HTTP will likely work. The camera is connected via Ethernet to the rowing club's infrastructure and is Powered over Ethernet.
On the rowing club's network is a raspberry Pi that runs a small service encapsulating an ffmpeg command that converts the RTSP stream to a format compatible with Youtube's free Live Streaming offering in YouTube Studio. You'll want to be sure to Schedule a live stream rather than go live directly. The scheduled streams will stay up and can be reused, live streams will get shutdown after a period of inactivity.
/var/lib/systemd/system/webcam.service
#
# Installed in /lib/systemd/system/webcam.service
#
[Unit]
Description=Webcam RTSP to Youtube transcoder
After=network.service
[Service]
User=pi
Type=simple
ExecStart=/bin/bash /home/pi/webcam.sh
Restart=always
RestartSec=90
[Install]
WantedBy=multi-user.target
/home/pi/webcam.sh
#!/bin/bash
#
# Installed in /home/pi/webcam.sh
#
YOUTUBE_URL="rtmp://x.rtmp.youtube.com/live2" # Server URL
KEY="your-youtube-streaming-key"
# Internal web camera IP is xx.xx.xx.xx
IP=your camera IP address
RTSP_PORT=your-cameras-rtsp-port
QUIET='-loglevel panic'
# Uncomment the empty QUIET variable below to see debugging output
#QUIET=''
ffmpeg ${QUIET} -hide_banner -ar 44100 -acodec pcm_s16le -f s16le -ac 2 -channel_layout 2.1 -i /dev/zero -i rtsp://your-camera-password@${IP}:${RTSP_PORT}/Streaming/Channels/101?tcp -rtsp_transport tcp -ss 2 -c:v copy -shortest -f flv "$YOUTUBE_URL/$KEY"
Use these commands to install and enable the service when the above two files are in place
sudo systemctl daemon-reload sudo systemctl enable webcam.service sudo service webcam start
Grabbing a still image from the webcam for use by Ambient Weather
The bash script below is run via crontab for the pi user every minute and captures a still image from the camera. Transferring this image to a public webserver with a URL that can be put into the Ambient Weather dashboard configuration is beyond the scope of this document.
#!/bin/bash
#
# Installed in /home/pi/webcam.sh
#
RTSP_IP=your-camera-ip-address
RTSP_PORT=your-camera-port
RTSP_USER=your-camera-user-name
size_download=0
min_expected_size=90000
retry=5
i=0
until [[ $size_download -ge $min_expected_size || $i -ge $retry ]]
do
size_download=`curl -s -w "%{size_download}" -o bayview-sample.jpg http://${RTSP_USER}@${RTSP_IP}:${RTSP_PORT}/Streaming/Channels/101/picture`
let i++
# echo $i $size_download
sleep 1
done
if [ $size_download -ge $min_expected_size ]
then
mv bayview-sample.jpg bayview.jpg
fi
Video Snapshot on the website
<a href="https://your-public-server/images/bayview.jpg" target="_blank"><img src="https://your-public-server/images/bayview.jpg" alt="Mission Bay" width="560" height="315" name="tcimage0"></a> <script> var tcimages = new Array(); tcimages[0] = "https://your-public-server/images/bayview.jpg"; interval = 15000; function Refresh() { ts = new Date().getTime(); for (i=0; i < tcimages.length; i++) { document.images["tcimage" + i].src = tcimages[i] + "?ts=" + ts; console.log('Refresh: ', ts ); console.log('document.images: ', document.images["tcimage0"]) } setTimeout("Refresh()", interval); } Refresh(); </script>
Live video on the weather page
This is the code that embeds a live YouTube video on a web page.
<iframe width="560" height="315" src="https://www.youtube.com/embed/live_stream?channel=your-channel-id&mute=1&autoplay=1" allow="autoplay; encrypted-media" allowfullscreen></iframe>