MQTT on the P2
From Wikipedia:
The Message Queuing Telemetry Transport MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. The protocol usually runs over TCP/IP; however, any network protocol that provides ordered, lossless, bi-directional connections can support MQTT.[1] It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited. The protocol is an open OASIS standard and an ISO recommendation.
MQTT is very strong in the IoT market. For the IoT market I think that this chip really needs MQTT, even more than it needs Python. And it already has Python.
I use MQTT. Before Covid I was teaching MQTT classes. Spoke about it at conferences.
There is the Paho MQTT client in C. It should port over easily and be quite small. 8K lines of C. Way way smaller than Python. Way easier to port. Of course it requires TCP/IP. And the TCP/IP story is not clear to me. There is a wifi board with applications, but I did not see a callable TCP/IP stack. Maybe I just have not found it yet. I think i read that there is UDP working. Some versions of MQTT do work over UDP and can provide guaranteed messages over udp. Hmmm. Maybe that would be a good path. There is also something called Zigbee, which I never heard of until today, but a quick search indicates that the P2 may support it.
Chris
Comments
Hi Chris,
to use MQTT with WLAN, some additional hardware system will be necessary. For example an ESP-32 based system or a little linux board. For ESP-32 MQTT is available as a library to the Arduino programming system. Together with good documentation and examples. But there are several other interesting things like for example Network Time Protocol and for these tested libraries and good documentation are available too. If you use a linux based system, you can use a samba ftp file server, or....
So instead of porting all these complicated libraries to P2 as the leading main system, I would like to suggest to see P2 as a subsystem to for example ESP-32. P2 has lots of port pins and can be a very powerful sensor- or actuator- frontend. Perhaps some good example how to connect and use P2 as frontend subsystem to ESP-32 would show powerful and versatile possibilities?
For MQTT I would use ESP-32 and perhaps let the P2 create the message string only. As communication protocol between the systems I would use tachyon forth as this already exists as a very good way.
Christof
The advice here has been just brilliant.
I strongly resisted the idea of a second microcontroller, but after some research, you are correct. That is the way to go.
And here is the spin object which talks to the ESP32.
https://github.com/parallaxinc/propeller/tree/master/libraries/community/p2/All/esp32
It is in the Parallax repository, so I assume it is good. Is anyone using it?
That should be good enough to get me started. And then if I want MQTT, your advice of MQTT on the ESP32, talking to Taqoz sounds about right. I have to do some programming on the ESSP32. Either also in C, or there are two forths that work with arduino on the ESP32. Then I will have 9 processors! Still some details to be figured out.
This link is interesting. It discusses development languages on the ESP32.
https://forums.parallax.com/discussion/172339/esp8266-iot-applications-written-in-forth-and-basic
Thank you.
chris
there is @"Peter Jakacki" 's IoT5500+P8 which combines a WIZNET 5500 EthernetChip with the P1 and SD on a very small module.
In Tachyon there is FTP/HTTP/Telnet servers for it.
I once wrote a scriptable webserver for it.
I was thinking of MQTT as well, but it appeared to much complexity.
(actually I did not spend enough time to completely understand the internals).
So a P2 with Taqoz and the Wiz5500 should easily be capable to run a MQTT - but s.o. would have to implement it ;-)
Wiznet sounds Great!
Connecting to a ESP32 deeply bothers me. Not beautiful. Practical, but not beautiful.
there is this great thread on the Wiznet chip.
https://forums.parallax.com/discussion/170587/p2-ethernet/p1
And particularly the posting by Peter.
Peter has all of the code to interact with it from Taqoz.
Of course all of the Tcp/IP handshaking is painful to implement. I can see why the ESP32 is tempting.
But with MQTT/UDP, all of that can be done in the broker, and in the client C program.
C program in one cog, talks to Taqoz in another cog, talks spi to a board. Maybe that board does not even plug into the Parallax Evaluation board. Also not an elegant solution.
Then there is this thread about all of the hard ware options.
https://forums.parallax.com/discussion/171766/p2-es-ethernet-dev-board-add-on/p1
Anyhow I am still learning. I am still not quite sure what I am going to do. Thank you for all of the help, and all of the pointers.
Chris
The following is posted in two separate threads.
If I have to run an ESP32 for Wifi Access, I can just load MicroPython on it, load MQTT on top of that, and speak to the primary cog, say a Spin cog over spi. Which can route the messages to and from the appropriate cogs.
Does that sound reasonable? It has several advantages.
Mainstream version of MicroPython and MQTT.
Python will run faster than on the P2.
No waiting for Round Robin memory access.
Get all of the advantages of the Smart pins.
All sounds quite easy to do.
Am I missing something?
the W5500 is doing all the low level - you just fill the buffers and read what is coming in
up to 8 - I think - sockets.
So Peter is running FTP/Telnet/4*HTTP and maybe SNTP ... in parallel
with Tachyon/P1
and no second MCU to program
you only need the MQTT client on the P2 or should it be the server?
is the server code much bigger than the client?
I would love to run s.th. like MQTT or even simpler on the P1 with SD-Card and Tachyon
For my needs I probably do not need full MQTT - only a simpler subset
which I was thinking to write.
on top of Peters TCP-Socket / HTTP / Telnet / FTP servers
You can do a search and then git clone on "Paho MQTT C".
then cloc to count the lines of code.
I am sure that the server is way bigger than the client.
Will it run on the P1? I do not know. Maybe.
Here is MQTT running on the ESP8266
https://github.com/martin-ger/esp_mqtt
Here is the 17 minute video.
There is also MQTT SN
http://www.steves-internet-guide.com/mqtt-sn/
The MQTT SN code will be smaller. Big picture, MQTT gives me a tree of topics, great for large organizations, MQtt SN just gives me a list of topics, fine for small applications.
But probably we will need to implement the client in Tachyon and port to Taqoz.
How hard will that be?
So first question is what is your spec?
Publish Subscribe?
UDP? TCP?
Guaranteed Message delivery?
Something else?
Warm regards
Christopher Lozinski
I really don’t see the Px as MQTT devices. It is obviously technically possible if you attach other components that do the network layers heavy lifting. But then these components essentially become so smart, they can do MQTT themselves.
Instead, let the Px do what it’s best for: low latency, low jitter, high number of attached devices due to pin count sensor data acquisition. And stream that over to a ESP or whatnot via serial protocol (pick any, I2C, UART, SPI), and that transforms into MQTT.
Great point.
Also I can buy an ESP board for the P2 today, but maybe not a W5500 board. I am not sure.
Let us see what @Mjb has to say.
the WizNet5500 is WIRED Ethernet -
not WLAN like ESP
so might not be what you want anyhow
the architecture I have in mind is very simple
ESP8266-Sensor/Actor-WiFi-1 ----- W
ESP8266-Sensor/Actor-WiFi-2 ----- L
ESP8266-Sensor/Actor-WiFi-. ----- A
ESP8266-Sensor/Actor-WiFi-n ----- N
IoT5500+P8-Module-with-SD&Tachyon-WEB-Server/FTP/Telnet ... ---- Ethernet -- Router/Repeater - WLAN -- Internet
Android-Mobile ---- WLAN /4G/5G locally or even Internet to Web-Server running on P1
The ESP-Clients are very simple probably NodeMCU/eLUA (I used before - very nice - works perfect with Tachyon)
on P1 only Tachyon to programm all my application - no other SW required
The scriptable Webserver can also provide the WEB-GUI
no dependencies to libraries etc.
Tachyon 5.7 in full source available
ESP32 does have Ethernet as well...
Really? I have used dozens and none had that. There might be variants with an attached Ethernet PHY, but I haven’t come across those.
Olimex has one
ESP32 POE
ESP32-POE-ISO
I am using the former for my tests
Nice product. I think the root cause of my confusion was the blanket statement "ESP32 does have Ethernet" - I took that as "all ESP32 do", which decidedly they don't. It wasn't meant that way I guess.
OTOH within the context of this discussion I wonder what the advantage of ESP + ETH PHY is. It appears as if in that scenario the W5500 is all you need. Unless of course you want WIFI, then sure.
ESP32 has Ethernet. That's referring to the chip itself, not any particular breakout board.
As for esp32 vs w5500, the w5500 is more expensive in bare chip form, and can't run your mqtt stack for you.
In fact all the ESP32 do ... except the S2 which is missing the Ethernet MAC, but it have the USB support
The W5500 module is more expensive than the otherwise required external PHY+RJ45 connector
Having both (the WiFi and Ethernet) MACs internally available simplifies the sw development and code re-usability for applications that can thus use both the media ... even at the same time and for any protocol