#MQTT with local broker

1 messages · Page 1 of 1 (latest)

merry grove
#

@chrome axle One wrinkle I ran into is that mosquitto requires nonlocal clients to authenticate.

chrome axle
#

I don't exactly know what you mean?

#

Hopefully tonight I have some time to start throwing some code in and seeing it work

#

Im not exactly using a local broker i dont think? The broker would be on the PI and the client would be the esp32?

merry grove
#

(In most of the Adafruit examples, they're using the MQTT broker at AdafruitIO, so it would be those credentials there.)

#

Anyway, I had to do some mosquitto configuration and set up a password file. I'll try to reconstruct what I did and post some details and links sometime today.

#

oh, by "local broker" I mean local to your place, under your control, vs. AdafruitIO or some other commercial broker. So yeah, on the Pi.

#

(Picked up that usage from one of the Adafruit guides.)

chrome axle
#

Okay. Sorry for my ignorance im so new to this stuff

#

ive been python programming for about a year. But always just gui / mysql type stuff. So this is quite new and exciting

merry grove
#

I know, it's great.

chrome axle
#

I definitely dont want to use the adafruit broker. I want this to all run without internet connection

merry grove
#

I've been programming with Python on and off since version 0.9, back in the 90s, and I still love using it.

chrome axle
#

this might be a silly question, But does my router just assign an IP to the esp32 when it connects using DHCP?

#

oh awesome

#

im an automation programmer for a living, robots, plcs, camera systems, hmis, servos

merry grove
#

Yeah, the default is DHCP, which stands for Dynamic something.

chrome axle
#

ive really starting joining the two worlds of PLC and Pthon to create databases off of our machines. Before this took very expensive software

#

since its publishing to a MQTT server with a specific topic the PI really doesnt care about the IP address because the topic is the unique identifier correct?

merry grove
#

My career was mostly server-side programming, mostly in C and then Java when that came out. So this hardware thing is relatively new to me too, but I've been playing with microcontrollers for a few years now.

chrome axle
#

Awesome

#

I think this project specifically is going to really give me alot more knowledge about it

#

I am currently running a furnace in my garage off of a raspberry pi

merry grove
#

Cool

chrome axle
#

but right now the temp sensor and furance are both wired into the PI

#

this will give me total wireless freedom.

merry grove
#

(I mean, warm 🙂 )

chrome axle
#

My garage is quite long. So I am going to add 3 wireless temp setups then average them

#

Its also very expnesive to heat because of poor insulation and it runs on propane. So I am going to add an ambient outside temp. So when I go in the garage its set to 65f. But when I leave the garage it will keep it at a minimum of 32deg or 10 deg over ambient

#

I also have a database logging to temp right now so I can pull all the stats. Currently im much more efficient then the old thermostat

merry grove
#

Sounds like a great and useful project!

chrome axle
#

Once thats all functional I am going to do my house. But to a different level. My house has rooms that are always different temps. So I am going to create a air duct register that I can open and close. So I will have individual room thems. So I can then open and close the vents depending on which rooms need the heat

#

thats pretty cool. I was just going to use the same setup because I have a shed that I could put it in thats water proof but not heated.

#

im mad when I left for work today i forgot to plug the esp32 into my desktop. I was going to remote in and setup the server programming lol

merry grove
#

Well, your job sounds like it has its attractions as well.

#

What's PLC?

#

programmable logic controller?

#

(That just means microcontrollers these days, right?)

chrome axle
#

thats right

#

and not really

#

because PLCs have their own programming language

#

its ladder programming. Very simple for the most part. But data handling is trickty

#

everything always runs in a loop

#

in automation every device I touch has different programming. Every PLC has their own version of ladder. Every Robot has their own programming syntax.

#

but its all pretty simple

merry grove
#

I'll stick to Python 🙂

chrome axle
#

I was trying to send you a video of a machine i did recently but discord has an 8mb limit

merry grove
#

I'd be interested, if you can post it elsewhere

chrome axle
#

my fricken phone videos are huge 1min 30 seconds 200mb

merry grove
#

The downside of hi-res

chrome axle
#

yep

#

and the new cameras are even more hi lol

#

im just stepping out for lunch I have an ftp I can send it to

merry grove
#

Thanks. I'll scrounge up the stuff about mosquitto configuration and post back here.

chrome axle
#

what is this chat window? is this public?

merry grove
#

It's a thread under help-with-circuitpython. You can see it listed under the icon at the top of the window that looks sorta like a pound sign followed by a digit

#

Just a way of moving a discussion out of the main topic

#

yeah, it's public

#

The mosquitto configuration stuff is all under /etc/mosquitto, with /etc/mosquitto/mosquitto.conf being the main config file.

#

You don't actually edit that though, as the comments in it explain.

#

So in /etc/mosquitto/conf.d, I made a file access.conf that looks like this

#
listener 1883
password_file /etc/mosquitto/conf.d/pwfile.txt
#

(The 'listener' is because it just wants to listen to the ssl port -- 6883?

#

In the password file, I started out with
tester:testing
then (inadvertently?) did something to encrypt the passwords; prolly wasn't necessary

#

man mosquitto_passwd describes managing the password file

#

user/pass goes in the corresponding parameters to the MQTT.MQTT call on the S2.

#

Clients running on the host a slightly different interface; client creation and connection is like:

import paho.mqtt.client as mqtt
# ...
client = mqtt.Client('testing')
client.on_connect = on_connect
client.on_subscribe = on_subscribe
client.on_message = on_message

client.username_pw_set('tester', 'testing')
msginfo = client.connect("127.0.0.1", 1883, 60)
chrome axle
#

thanks for the info

#

i sent you a PM with the link for the machines

#

how do I get the paho lib onto the microcontroller?

merry grove
#

The paho lib is for the PI; you're using adafruit_minimqtt on the mcu

chrome axle
#

oh okay

merry grove
#

The minimqtt lib is described as modelled on the paho one, but obviously different in setup to account for not being able to assume a network connection is there for the taking

chrome axle
#

how would you suggest starting on the project. I have a MQTT server going. So should i start with the microcontroller trying to push data? Is there a way to see that the server is receiving it? or do I need both ends working

merry grove
#

That's why I have a 'read everything' client running on the Pi. I'll post the code after a bit -- need to do something here for a while.

#

So yeah, I think you need to get the authentication stuff working, and you need a subscribing client to see what's being published.

chrome axle
#

no problem. I am just hoping I have time tonight to work on it lol

#

im in process of building a new race car lol

merry grove
#

(Slightly cleaned up for sharing; I don't think I broke it in the process)

chrome axle
#

thanks for the program

merry grove
#

In the on_message function, you'll see that the message is bytes or a bytearray; by default in minimqtt, messages are strings instead.