Hi Ralph,
I think your suggestion is the closest to what I was envisaging, so I had a
bit of a stab at it this morning.
Created a ReadMqttScript.py file, copied your script into it and made it
executable. Changed your IP address to the one I'm using (192.168.1.130)
and gave it a try:
weewx@raspberrypi:~ $ ./ReadMqttScript.py
Connected with result code 0
^CTraceback (most recent call last):
File "./ReadMqttScript.py", line 46, in <module>
client.loop_forever()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line
1578, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line
1057, in loop
socklist = select.select(rlist, wlist, [], timeout)
KeyboardInterrupt
It will sit at "Connected with result code 0" for as long as I leave it
there. I assume it's something to do with the IP address I'm telling it to
connect to - I have tried "localhost" and "127.0.0.1" (the broker and weewx
run on the same RPi) but to no avail either. Certainly no filepile is being
produced in the /var/tmp directory.
The broker is working - I am able to see the sensor post to it via the PC
I'm working from.
If anyone has some time to provide some advice it would be most appreciated
- I'm most definitely at the lower end of competence when it comes to doing
much more than following guides.
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.