Updated Guide: Weewx, Nginx, Belchertown, MQTT/WS

Belchertown Weewx Skin/Extension

Here comes the fun part, the Belchertown weewx skin! The entire source and dev process for this amazing weewx extension/plugin can be found here: https://github.com/poblabs/weewx-belchertown

Here’s the steps for this entire process.

  1. cd ~
  2. wget https://github.com/poblabs/weewx-belchertown/releases/download/weewx-belchertown-1.1/weewx-belchertown-release-1.1.tar.gz
  3. /home/weewx/bin/wee_extension --install weewx-belchertown-release-1.1.tar.gz
    The extension should successfully install, and it should modify weewx.conf with relevant data. We’ll need to modify that shortly, alongside the skin.conf file in the Belchertown skins folder.
  4. When you installed weewx, it should have asked for your location, latitude, and longitude, along with elevation. If not, you need to add it to the [Station] segment within weewx.conf.
  5. station_url needs to be set to the domain, excluding end-slash. For me, it looks like this:
    station_url = https://weewx.potatoforinter.net
  6. Within [StdRESTful], you should see [[MQTT]] with its associated variables listed below. You will need to update the username and password field, along with the IP address where the mosquitto daemon resides at. The username and password is what you set earlier with mosquitto’s passwd file. Mine looks like the following (password redacted with something cheesy).
        server_url = mqtt://weewx:AnAmazinglyComplicatedPassw0rd@
        aggregation = aggregate
        topic = weather
        unit_system = US
        binding = loop,archive
  1. Next, we scroll down to the skins segment, this is within [StdReport]. Set or ensure that [[SeasonsReport]], [[SmartphoneReport]], [[MobileReport]], and [[StandardReport]]‘s enable are all set to False.
  2. If not added to [StdReport], add the following…
        HTML_ROOT = /var/www/html/weewx
        enable = True
        skin = Belchertown
  1. Ensure your HTML_ROOT is /var/www/html/weewx. There is no need to dump the content to the main web root, nginx handles the vhosting for that stuff!
  2. Save weewx.conf, we’re heading to skin.conf!

Belchertown Configuration

The fun begins here. Belchertown supports HighCharts.com graphing, so as long as your database supports said variables, weewx will dump the needed data to Belchertown and make some really pretty graphs. That won’t be covered in this writeup, and you’ll need to check the Belchertown github page for that.

Time to add/modify the configuration for MQTT to the skin.conf file.

  1. nano /home/weewx/skins/Belchertown/skin.conf
  2. We’ll be editing just about everything in the [Extras] section.

General Site Defaults

You’ll want something like this… 0 is off or false, 1 is on or true.

    # General Site Defaults
    check_for_updates = 0
    belchertown_debug = 1
    belchertown_locale = "auto"
    theme = dark
    theme_toggle_enabled = 0
    site_title = "This Appears On The Web Site Header - So do not make it long!"
    logo_image = ""
    radar_html = ""

Next, we’ll be updating station_observations. If you have a weather station that supports said data (Davis Vantage Pro2+), keep it in this list, otherwise, remove it from this list – as it’ll be a 0/null value. appTemp is Apparent Temperature, which appears to be a “Feels Like” temperature – I’ve not dug into the source code to know how it is exactly calculated.

These data points are fed from the loop/realtime/rapidfire/whatever you want to call it – packets.

station_observations = "barometer", "dewpoint", "outHumidity", "appTemp", "windchill", "heatindex", "radiation", "UV", "rainWithRainRate"

Now for the Manifest and High Charts segment. Manifest Name and Short Name need to be something unique. I set mine to being the domain name words + wx.


These settings are fairly straight forward. You only need to modify highcharts_homepage_graphgroup if you are making a fully custom home page of custom graphs.

    # Manifest Settings for Mobile Phones
    manifest_name = "PFI-WX"
    manifest_short_name = "PFI-WX"

    # Highcharts settings
    highcharts_enabled = 1
    graph_page_show_all_button = 1
    graph_page_default_graphgroup = "day"
    highcharts_homepage_graphgroup = "homepage"
    highcharts_decimal = "auto"
    highcharts_thousands = "auto"


So, recall how we didn’t explicitly set SSL details on mosquitto? Yeah? Good news – nginx is still handling that. Our config will look like this for the WebSockets/MQTT section…

    # MQTT Websockets defaults
    mqtt_websockets_enabled = 1
    mqtt_websockets_host = "weewx-socket.yourdomain.com"
    mqtt_websockets_port = 443
    mqtt_websockets_ssl = 1
    mqtt_websockets_topic = "weather/loop"
    disconnect_live_website_visitor = 1800000

As you can see, we are routing weewx-socket.yourdomain.com via port 443. Nginx ingests that subdomain name on 443/SSL and automatically sends it internally to port 9001 on the mosquitto WebSocket listener port. Pretty handy, right? No need to open up obscure ports on a firewall with this method!

Final Extras…

The following are miscellaneous options for the Belchertown weather skin. Enabling more features is optional, but is worthwhile (IMHO!). Set these as you please. Your lat/lon values from weewx.conf will be used for the earthquake distance values.

NOTE: The DarkSky API will be disappearing by the start of 2021 as Apple.com bought them out. At that point, a new alternative may be available for reliable forecast data.

    # Show an alert if the page updated timestamp is older than expected with this setting. Does not apply to MQTT Websocket enabled websites
    # The late time threshold is defined in seconds. This should be greater than your archive_interval from weewx.conf.
    # Typically you would want this 2 or 3 times archive_interval
    show_last_updated_alert = 0
    last_updated_alert_threshold = 1800

    # If mqtt_websockets_enabled is set to 0, but want the page to full reload on an interval, specify this below in milliseconds. 300000 = 5 minutes
    webpage_autorefresh = 0

    # Image Reload Section.
    # Set reload_hook_images to 1 to enable, then set the number of *seconds* for each section to reload.
    # A value of -1 will disable reloading images in that section.
    # radar = the radar image if you used radar_html setting
    # asi = index_hook_after_station_info.inc
    # af = index_hook_after_forecast.inc
    # as = index_hook_after_snapshot.inc
    # ac = index_hook_after_charts.inc
    reload_hook_images = 0
    reload_images_radar = 300
    reload_images_hook_asi = -1
    reload_images_hook_af = -1
    reload_images_hook_as = -1
    reload_images_hook_ac = -1

    # Forecast defaults
    forecast_enabled = 1
    darksky_secret_key = "YourAPIKeyGoesHere"
    darksky_units = "auto"
    darksky_lang = "en"
    forecast_stale = 3540
    forecast_alert_enabled = 1

    # Earthquake defaults
    earthquake_enabled = 1
    earthquake_maxradiuskm = 1000
    earthquake_stale = 10740

    # Social Share Button Defaults. Define the text below under Labels
    facebook_enabled = 0
    twitter_enabled = 0
    social_share_html = "http://yourwebsite"

    # Google Analytics
    #googleAnalyticsId = UA-12345678-1

    # This is the display of the Pi Kiosk which is in the /pi folder
    pi_kiosk_bold = "false"
    pi_theme = "auto"

Save the skin.conf file.

Issue restart commands for weewx, nginx and mosquitto.

  • service weewx restart
  • service mosquitto restart
  • service nginx restart

If all three restart without error, try and access your weewx weather site. You can see mine in operation at https://weewx.potatoforinter.net/ 🙂

As always, if you have a question or need assistance – pop a comment in the Disqus box below.