Hi Ralph,
I think that your way of doing things is the closest to what I had
envisaged.
Thus far I have managed to create a .py script that I can run manually by
copying and pasting from yours, modifying the IP address to 'localhost' as
they are both on the same RPi.
Watching the log of the MQTT broker, I can see that the script is indeed
connecting and if I stop the broker and start it again I can see the script
reconnecting as it is supposed to:
weewx@raspberrypi:~$ ./ReadMqttScript.py
Connected with result code 0
What I am not seeing is an output to /var/tmp/filepile.txt - is there
anything else that I might need to do before that will happen? I am able to
see from another PC that the broker is indeed publishing
"weather/temperature" and "weather/humidity" so I am a bit lost as to what
could be going wrong.
*sigh* I haven't even got to modifying the weewx code yet..
On Sunday, 7 April 2019 02:52:06 UTC+13, Ralph Underwood wrote:
>
> 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.