I have a small python program that subscribes to mqtt and writes a text
file. I then use the filepile as a service to get the data into WeeWx. The
"main" data comes from a Ultimeter station via the driver.
I came up with this approach while I was modifing/testing using the
WeeWxMQTT driver a service. It works and I put the conversion to a service
on the back burner.
#!/usr/bin/python
import syslog
import time
import ftplib
import time
import logging
import paho.mqtt.client as mqtt
MQTT_SERVER = "10.0.1.47"
MQTT_TOPIC = "weather"
# The callback for when the client receives a CONNACK response from the
server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe(MQTT_TOPIC)
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
#print(msg.topic+" "+str(msg.payload))
#print(str(msg.payload))
m1 = (msg.payload).replace(':',' = ')
m2 = m1.split(",")
m3 = m2[1]
m4 = "soilTemp4 = 32"
file = open('/var/tmp/filepile.txt' , 'w')
file.write(str(m3)+'\n')
file.write(str(m4)+'\n')
#print(m3)
#print (m4)
#print("file stent")
file.close()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(MQTT_SERVER, 1883, 60)
client.loop_forever()
There are some print lines which are commented out for debugging. I also
use this to set soilTemp4 to 32 degrees - that's so I can easily add a
freezing level line on charts.
from weewx.conf:
# Options for extension 'filepile'
[FilePile]
# Where to find the incoming new data:
filename = /var/tmp/filepile.txt
# What unit system they will be in.
# Choices are 'US', 'METRIC', or 'METRICWX'
unit_system = US
# Map from incoming names, to WeeWX names.
[[label_map]]
# Example: incoming observation 'filelabel1' will be mapped to
'extraTemp4'
INTE = extraTemp2
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.