ESP8266 MQTT Client

Special solutions for outdoor model railroading.

Re: ESP8266 MQTT Client

Postby gramels » 22.01.2017, 07:57

Hi Dagnall,

I presented your solution at the Rocrail User meeting in Speyer with great feedback and increased interest. Keep up the good work. I will make an instruction page in the rocrail wiki soon.

Please find my slides at
viewtopic.php?f=82&t=12546&start=30#p135538

Thanks for the great work.

Lothar
openDCC - MultiMaus - (MERG RFID) - testing a planned garden layout in IIm -
gramels
 

Re: ESP8266 MQTT Client

Postby Dagnall » 15.02.2017, 14:09

I thought you might like to see my "Station" wiring using the NodeMCU.
I have connected cheap ebay modules together very simply using standard breadboard push connectors. There is a Dual Motor driver, an AC-DC 5V regulator and a NodeMCU.
These are all located on a 3d printed "plugboard". http://www.thingiverse.com/thing:2079062
I then added four long 3 way extensions, (2 servos and 2 sensors). these plug neatly on the 5V regulator, with additional short wires to connect to the relevant ESP8266 pins.
There are then two ESP outputs sent to the two motor drivers (one each, ..no reversing!..).
I use the PWM drivers to adjust some filament lights in the servo points.
The 5V regulator has been modified to send "raw" DC to the motor driver, but that (and a correction to the 5V regulator circuit (!)) was the only real soldering.

Perhaps we can persuade Peter Gilling to improve on this to make a PCB for it that is smaller and neater ? :wink:

IMG_1167.JPG
You do not have the required permissions to view the files attached to this post.
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Updates to ESP8266 MQTT Client

Postby Dagnall » 10.10.2017, 13:12

I have updated my ESP8266 NodeMCU client.
It now reports that it has a Pi 02 and a Pi 03, rather than a random selection!. (although you can easily change it so it reports neither if you prefer!)
{FYI, the hardware supports 8 I/O that can each be programmed as digital IO (like a Pio2), or as Servo/PWM (like a Pi03).}

I have significantly improved the servo codes, as the previous versions were very slowed down by some debug serial messages.
I have also added a debug that works over MQQT, so you can easily see which nodes are on line and when they send messages. (useful for debugging).
I have added Over The Air software updating , This works with the Arduino interface and means that you do not have to kneel in the mud with a USB interface to update the nodes in the garden!.
I have also updated the Mobile part of the code and it works as a single channel controller for a Loco with front and rear lights and a servo controlled motor. (with 4 spare I/o for other things if you need them).
IMG_1691.jpg

My hardware now uses the "L293D Motor Shield Module", easily available from E-Bay and other places.
As well as providing some screw terminals and the L293 IC, this useful and inexpensive module takes all the NodeMCU ports out and provides them on a row of standard servo type 3 pin interfaces. --- Unfortunately it supplies the V+ to this row from the NodeMCU 3.3V regulated output, so it is not immediately useful for standard 5V servos, but a very simple cut of one track on the back of the board isolates the V+ on this row and allows you to connect these instead to "Vin". BY then adding a simple external 3 terminal 5V regulator between the +12V and "Vin" screw terminals, you can use the module with a single 12V power source, provide +5 regulated to the NodeMcu (and the servos/ sensors). The ModeMCU ports D1- D4 are connected to the inputs of the L293 and can be used for two motors or PWM (12V) outputs.

NodeMCU Mods.jpg

IMG_1682.jpg


Code is still at https://github.com/dagnall53/ESPWIFIROCNET
Cheers
Dagnall
You do not have the required permissions to view the files attached to this post.
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby Dagnall » 10.01.2018, 19:36

I have been working :coding: on the Loco with Sounds and I have put an initial version of my ESP8266 (nodeMCU) code on GitHub.
https://github.com/dagnall53/ESPMQTTRocnetSound

A video of the code (without the loco hardware, but with a steam generator) is here:
https://www.youtube.com/watch?v=Vd0HbV_MXVI

:beer:
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby Liviu M » 10.01.2018, 21:48

Hi Dagnall,

really nice!

Thanks for sharing it,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 MQTT Client

Postby Dagnall » 27.02.2018, 19:07

The latest version of the mobile version can now play 2 sounds simultaneously, so chuffs and sound effects can play together. A great improvement, and all thanks to Earle Philhower's ESP8266 Audio Library.
There is a YouTube video of the latest version here:
https://www.youtube.com/watch?v=Pg5r6MZDhww
The code is available on Github. https://github.com/dagnall53/ESPMQTTRocnetSound
Cheers
Dagnall
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby Dagnall » 09.05.2018, 14:04

I have added a lot of user pages with information about the code, the variants for locos and static nodes and hardware, as well as my wireless RocClient throttle and wireless RocClient switch adjustment tool:
Start here: http://wiki.rocrail.net/doku.php?id=users:dagnall53:description and explore! ...
:coding: :!: :D :thumb_up:

If you have questions, just ask in this thread...
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby RedTrain » 09.05.2018, 16:06

cool stuff - thanks! :thumb_up: :D
Beste Grüsse kind regards, Carlo

[H0m 2L DCC] Layout "Rhaetian Flyer" Proto-Freelance Swiss meter gauge RhB+MGB+zB; 7% completed, stage 1 operational
W10-64, WLANmaus, Rocweb, andRoc; CANbus GC1e, GC3-ORD3, GC2, GC6; Bemo, Peco, handlaid;
RedTrain
 

Re: ESP8266 MQTT Client

Postby janvanderborden » 09.05.2018, 18:43

HI Dagnall

I send you a PM with the question about defining D9 ?, did you read it ?
gr jan
janvanderborden
 

Re: ESP8266 MQTT Client

Postby Dagnall » 09.05.2018, 19:05

janvanderborden wrote:HI Dagnall

I send you a PM with the question about defining D9 ?, did you read it ?

Sent PM response just now.. :D
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby casperdeboer » 06.09.2018, 16:41

Hi

I want to make an switching table and was wonder how the mqtt message loks like for switching a servo?
i know teh topic is rocnet/ot but how do i get the message to the right node?

Casper
casperdeboer
 

Re: ESP8266 MQTT Client

Postby Dagnall » 08.09.2018, 13:18

Casper

I have not yet tried anything with a turntable, but I suspect that using a servo may not provide sufficient accuracy to align the tracks. Peter Basti has some info on turntables on his user page: https://wiki.rocrail.net/doku.php?id=userpages:peter-basti:turntable
and there is some more here: https://wiki.rocrail.net/doku.php?id=drehscheibe-de

Rocnet adddressing uses Rocnet node addresses, and for my ESP code, the Rocnet node id for each separate ESP unit is (initially) the same as the last digits of its IP address. This ensures that each Rocnet node has a unique address. You can change the Rocnet node ID using the standard interface in Rocrail, , but I would not recommend it as accidentally having two the same makes for big problems!

You suggest the mqtt group (See https://wiki.rocrail.net/doku.php?id=rocnet:rocnet-prot-en#groups) is /ot, but I use /st in my code so I set and change "port" status. The only "servo" messages I use in my ESP code are therefore the standard port "switched" and "straight" messages, which are then interpreted by the code in the decoder to the appropriate servo angles. I cannot send a specific "servo angle".

You will have to ask Rob how the "output" works. the explanation in https://wiki.rocrail.net/doku.php?id=rocnet:rocnet-prot-en#output looks rather small and needs some more explanations :wink: Sorry.-- but I look forward to following your conversations with Rob! :D

You may find some help on how MQTT code works if you can explore my experimental "switchtool" code https://github.com/dagnall53/SwitchTool This uses MQTT "direct" and interrogates Rocrail to see and set servo positions for switches(turnouts). It finds each servo and then sends messages including their (rocnet ID) address and switch position.



Sorry not to be more helpful.
Dagnall
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

Re: ESP8266 MQTT Client

Postby casperdeboer » 13.09.2018, 05:17

Hi Dagnall

Thnx for your reaction and all the info. What i want is an tableau on witch there are swirchs to controll servo's, i am using the esp wifi rocnet master and i am having problems with resetting is this normal? in combination with a nodemcu hoocked up to my laptop because i am still in testing mode and if it aint what can i do about it. And if i am using the input with an hallsensor for detecting it seems to work as an toggleswitch?. I Hope you van help me out.

Thnxx
casperdeboer
 

Re: ESP8266 MQTT Client

Postby casperdeboer » 13.09.2018, 05:19

i will order an wemos tool from china
casperdeboer
 

Re: ESP8266 MQTT Client

Postby Dagnall » 13.09.2018, 11:48

Casper.
There is lots here, but I hope that if you can follow all this you should have a good enough understanding to be able to use the modules as you want.

Just to check and confirm I understand your question; I am assuming you are using Rocrail to control everything, so the "switches" are the points/switch symbols on rocrail, (and will control the real world by servos, and that you are using the Hall sensors on the ESP to detect trains.

If you have Rocrail setup, and one of my RocnetESP nodes working, then when you select {rocrail}Programming/Rocnet/Setup and press "Query", you should see the esp ID and some data for the working ESP rocnet node...
(getting this far sometimes takes a few restarts of Rocrail if you are changing things like the MQTT IP addresses...)
Code: Select all
ID  Location Vendor                     Class Revision i/o Sub IP   UID name
28  0  Public Domain and DIY Decoders   Al     13       8    0.22     WoodSt

Here the ESP is at real IP address xxx.xxx.xxx.22 but has a Rocrail ID of 28, and a UID name of "Wood St". This module is using revision 13 of my code.
IF this is not working it may be that your ESP is not connected properly to your wifi. Please start it using the arduino interface and it should help you identify the problem using the arduino terminal.


If you get this far, you should then be able to check and see the various Port settings for this ESP module.
Typically for an INPUT on PORT 4, I will set the PORT 4 PI02 Port setup for the port as follows:
Set Type to "Input", and then, because of the hall pulling "down" on detecting the magnet, I set "Invert" ON.
I do not set Toggle. { I do not think my ES code even recognises toggle, but I could be wrong}
{The PORT 4 PI03 PORT settings are ignored because this Port is an "Input" as set by the Pi02 Settings)

Test this with a magnet and you should see the sensor icon (with the interface set to address 28,Address 4,type sensor) on Rocrail go RED when you place a magnet near the sensor, and the blue light on the NodeMcu module should change to blue.
In the rocrail controller viewport, rocrail should report something like this:
Code: Select all
10:58:19 sensor report 28:4 off code= load=0
10:58:18 sensor report 28:4 on code= load=0


To help testing, my code sends special MQTT debug messages to "debug"
In command prompt (switch to your mosquitto directory) and use the command "mosquitto_sub -h 192.168.0.11 -i "CMD_Prompt" -t debug -q 0
(assuming your mosquitto is at 192.168.0.11 !!)
and you should see something like this...
Code: Select all
C:\Users\Richard>cd C:\mosquitto

C:\mosquitto>mosquitto_sub -h 192.168.0.11 -i "CMD_Prompt" -t debug -q 0
<11:04:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF
<11:04:70s>  Node:28 (Wood St) Msg:*Sensor Seen&Sent  Address:4 state:1
<11:04:70s>  Node:28 (Wood St) Msg:*Sensor Confirmed Address:4 state:1
<11:04:73s>  Node:28 (Wood St) Msg:*Sensor Seen&Sent  Address:4 state:0
<11:04:73s>  Node:28 (Wood St) Msg:*Sensor Confirmed Address:4 state:0
<11:04:77s>  Node:28 (Wood St) Msg:*Sensor Seen&Sent  Address:4 state:1
<11:04:77s>  Node:28 (Wood St) Msg:*Sensor Confirmed Address:4 state:1
<11:04:77s>  Node:28 (Wood St) Msg:*Sensor Seen&Sent  Address:4 state:0
<11:04:77s>  Node:28 (Wood St) Msg:*Sensor Confirmed Address:4 state:0
<11:05:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF
<11:06:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF


Note that the Time Synchronisation is sent to the debug port, so this is a very useful way of checking all your Esp devices are actually connected. For this reason I usually run the debug all the time in the background so I can check if something has lost connection..

Now, using the interface in Rocrail,
First, note that the hall sensor will only close momentarily when the train passes over it, so I set the block sensors to "enter2in".
Consider this very simple track with two terminal type sidings and a single point(/switch):
[Station Back] Sensor{SR} ... Point Thrown
[Station Front] Sensor {SF}... Point Straight ------ Main Route.
The "SR" sensor (say ID28 port 4 for example) after the points(thrown) detects the train just as it starts to enter block "StationBack" You do this by having the (Tables/blocks/ (chose StationBack) and then "routes", "all enter+" and "all enter -" and set the ID of the sensor to "SR" and the "Event" to enter2in for both these entries.
When the sensor detect the train, the sensor will momentarily go green, and Rocrail will know the train is now in that block. You can do more complex sensor patterns, with entry and exit sensors, but I have not played with thes, as the enter2in event is ssuitable for all my needs.

For the Switch for the points its very similar except that the settings for a port (example here is PORT 7) to be a servo output are as follows:
Pi02 Port setup for PORT 7 set to OUTPUT
Pi03Channel Setup for PORT 7: Left and right set the servo positions. I would set left and right steps to "1" to start with. Set the "Servo" tick box, but leave the Blink box unchecked. Set Delay*10ms to "1".

Providing you have placed a point/switch on your layout, and set the propertiies: {General: Type: Switch} [Interface InterfaceD {whatever you called your MQTT controller} Bus : {28 in this example} Address {7 in this exmple for PORT 7 with a servo connected} {and Check Single Gate}.
With these settings rocrail should be able to change the switch/point/servo position.
The debug monitoor should show something like this
Code: Select all
<11:21:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF
<11:22:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF
<11:23:20s>  Node:28 (Wood St) Msg: IPaddr .22  Time Synchronised. Power is OFF
<11:23:24s>  Node:28 (Wood St) Msg:Setting Output 7 (SERVO) to State(1) = Position:180
<11:23:26s>  Node:28 (Wood St) Msg:Setting Output 7 (SERVO) to State(0) = Position:4


I think if you can get all this working, you should be able to make what you want work, and experiment with the other settings, to get things like the PWM controls and blinking working for lights on the track...
good luck
Dagnall
ESP8266 Based RocNet Universal 8 i/o decoder and Mobile Decoder. http://wiki.rocrail.net/doku.php?id=users:dagnall53:description
G Scale 3D printed Locos and wagons : (on Thingyverse)
Dagnall
 

PreviousNext

Return to Garden Railroads