Mobile RCP Rocmouse

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 05.04.2018, 12:11

I am not sure I understand your somewhat cryptic response... sorry. :oops:

I have a bat file that makes my loco go forward:

Code: Select all

CD C:\\
cd mosquitto
mosquitto_pub -h 192.168.0.18 -p 1883 -t rocrail/service/client -m "<lc addr=\"2636\" V=\"10\" fn=\"false\" dir=\"false\" usesecaddr=\"false\" throttleid=\"PUBtest\" />" -q 1 
The attached loc speed test trace shows where I sent this (line 3267).
- This code "works", in that the loco moves. BUT the Rocview throttle does not show any changes...... I was hoping/expecting that the Mode for the loco would show "PUBtest", and the V__ would change to "10"
(I stop the loco using the Rocview throttle at line 3332).

What I would like is for Rocview to show the throttle position (etc). What do I need to do for this to happen, is there an "update" command or something?

As a secondary issue, how do I get data "back" into the client(hand held throttle).. For example, how can I "read" the current throttle setting? I have tried subscribing to rocrail\service\info, but I have not seen any activity there..
And all I see when subscribing to rocrail/service/client is the commands I send. (see below) Not like the "broker response" example in http://wiki.rocrail.net/doku.php?id=roc ... tt_service

Code: Select all

C:\mosquitto>mosquitto_sub -h 192.168.0.18 -i "rocrail" -t rocrail/service/client -q 1
<lc addr="2636" V="10" fn="false" dir="false" usesecaddr="false" throttleid="PUBtest" />
Hoping for a simple answer I can understand :wink:
Dagnall
Attachments
loc speed test.trc
mqtt speed test
(283.42 KiB) Not downloaded yet

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 05.04.2018, 13:09

HI Dagnall,

you did forget to set the loco id.
If set, Rocview will show it.

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 05.04.2018, 13:16

Hi Dagnall,

just read the Wiki:
http://wiki.rocrail.net/doku.php?id=roc ... tt_service

for subscription you have to use another topic.

Code: Select all

pi@raspi9:~ $ mosquitto_sub -h nasrr -p 1883 -t rocrail/service/info
<clock divider="1" hour="14" minute="14" wday="4" mday="5" month="4" year="118" time="1522930442" temp="20" cmd="sync"/>
<clock divider="1" hour="14" minute="15" wday="4" mday="5" month="4" year="118" time="1522930502" temp="20" cmd="sync"/>
<clock divider="1" hour="14" minute="16" wday="4" mday="5" month="4" year="118" time="1522930562" temp="20" cmd="sync"/>
<clock divider="1" hour="14" minute="17" wday="4" mday="5" month="4" year="118" time="1522930622" temp="20" cmd="sync"/>

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 05.04.2018, 14:06

rjversluis wrote:HI Dagnall,

you did forget to set the loco id.
If set, Rocview will show it.
Excellent :D (although it was not "forgetting", just "not knowing")...

Addiing id=\"Black Terrier\" makes rocview show the changes.. Thanks. (It also works with the fn code I copied earlier).

Code: Select all

mosquitto_pub -h 192.168.0.18 -p 1883 -t rocrail/service/client -m "<lc id=\"Black Terrier\" addr=\"2636\" id= V=\"10\" fn=\"false\" dir=\"false\" usesecaddr=\"true\" throttleid=\"PUBtest\" />" -q 1 
Makes the throttle move on the PC! and shows the throttle ID in the Mode

Now I need to find out how to get the ID (Black Terrier in the example) to be read from Rocrail into my controller.
I will explore your later response in more detail.

but I had read that wiki and have tried a mosquitto sub to info.. I must have made some erros and will check as I got nothing showing, not even time signals...

D

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 05.04.2018, 14:10

Hi Dagnall,

you can try this to get the loco list:

Code: Select all

<model cmd="lclist"/>

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 05.04.2018, 16:24

rjversluis wrote:Hi Dagnall,

you can try this to get the loco list:

Code: Select all

<model cmd="lclist"/>
Excellent, and thanks again. Sending this brings up my loco list on my mosquitto subscription to rocrail/service/info.
<model cmd="swlist"/> lists all my switches... Very useful for my next part, which is using the hand controller to SIMPLY adjust servo point positions....

Lots of coding to do so I can extract the data I need to mke the hand controller work "nicely" with Rocrail, and to set up menus, but I can at least now see most of the path out of the forest (I hope).. :coding:

One super irritating thing about the off the shelf hardware (wemos with joystick, battery and LCD) is that the "left" button is wired to reset.. so that makes an ergonomic menu more challenging.. (Or I may see if I can cut the trace easily..)
If you feel the need to check out this very inexpensive hardware I am trying, look for something like this on ebay : "Screen ESP-8266 Module 18650 Battery"


Cheers. Thanks for your help
Dagnall

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 08.04.2018, 16:49

Rob,
The controller project is going well, BUT...The lclist and swlist responses sent by Rocrail are HUGE in terms of MQTT data.. I can read the packets, but I had to modify the MAX packet size in pubsubclient to avoid that library rejecting the messages as being too long...Even for a very small layout, I am getting a MQTT Loco list of about 300 bytes per loco, and my switch list is already 14kb. This places quite a load on the software that is trying to read this data.

What you send at present is a fully concatenated list of all items, all in one packet. This overwhelms some mqtt code and gets bigger for big layouts. What I would like to ask is : "was this concatenation essential?", and, "is there an alternative?"

I have had some thoughts about improvement and what I would like to request is a feature so the lists can be published in smaller, "de-concatenated", packets.

I was hoping it be possible to have a version of the lists that breaks each "list item" out as a separate MQTT message: ??
Something like this:

Code: Select all

1st message "<swlist    <sw {data for first list item}.........  </sw>"
2nd message "<sw {for the next item } .. ending with </sw>"
....
Last message "<sw{ last sw item} ....</sw> </swlist> ?
OR perhaps this may be simpler to code:

Code: Select all

1st message "<swlist> "
2nd message "<sw type{first list item}.........  </sw>"
3nd message "<sw {for the next item } .. ending with </sw>"
....
penultimate message "<sw {for the last list item } .. ending with </sw>"
Last message "</swlist> ?
(same of course for the loco list and any others....)

This way the MQTT messages will have a maximum data size that is not dependant on the number of items in the list, so should not crash when the layouts get complex.

The new format could perhaps called by a new "deconcatenated listformat" { such as "model cmd="lcdelist" }

or, ... perhaps this transmission format could be be selected by a new model cmd attribute variable added to the swlist and lclist commands.... Perhaps "ListConcatenate="false"? (This would default to ListConcatenate= "true", so the default sends the whole list as a single MQTT message in the concatenated form as at present).

Of course there may be a similar feature that already does this that I have not understood or explored...??

Sorry message is so long.
Dagnall

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 08.04.2018, 17:00

Dagnall,

whats the problem? MQTT or your program not able to process those few chars?

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 09.04.2018, 11:32

The MQTT library (Pubsubclient) has a default maximum message content limit of 128 bytes for the message payload.
.... "those few chars" :wink: are actually a single 13kbyte(+) block of string at the moment. We have to store this full list in one go before reading it and doing what we need to extract the actual data we need for throttles etc. I have accepted the big message at the moment by changing the default max message size, but this means the program has an ultimate limit based on available memory.

I've currently got about 20kbyte for this variable in my test code. This is quite a lot for a small processor!. And if the layout gets bigger it will run into a message length limitations.

I would like the code to be able to run with virtually any size layout, so would like to remove or bypass this MQTT message length issue.

My suggestion would reduce each message to circa 600 characters per list entry, and each message would not get bigger as you increase the size of the layout (or add more locos). (But there would be more messages of course). We can then read the list in smaller chunks, getting the data we actually want from each chunk in series.

You can see from this simple example with two locos, how the list would split nicely into separate messages if it was broken to a new message after each "</lc>"
locolist.txt
<lclist> data for two locos
(6.67 KiB) Downloaded 2 times
D

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 09.04.2018, 11:56

You are connecting to the Client channel with all its features.
If your firmware cannot handle it you should rethink your design.
If MQTT has a message limit size, its not the way to communicate; Try a direct TCP/IP connection.
There are XML parser libraries which can parse chunk by chunk of an XML stream. (SAX)

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 09.04.2018, 12:27

There are XML parser libraries which can parse chunk by chunk of an XML stream.
I think that may be the way to go.. Any suggestions as to a good library to start with?

More exploring.... :coding:

D

janvanderborden
Posts: 588
Joined: 06.09.2014, 16:23
Location: Heiloo

Re: Mobile Rocmouse

Post by janvanderborden » 14.04.2018, 20:31

Hi Dagnall

Can you give me a hint . When compiling i get the next error:

In file included from C:\Users\Jan\Documents\Arduino\libraries\ESP8266Audio\src/AudioGeneratorFLAC.h:24:0,

from C:\Users\Jan\Documents\Arduino\libraries\ESP8266Audio\src\AudioGeneratorFLAC.cpp:21:

C:\Users\Jan\Documents\Arduino\libraries\libmad-8266-master/AudioGenerator.h: In member function 'virtual bool AudioGeneratorFLAC::begin(AudioFileSource*, AudioOutput*)':

C:\Users\Jan\Documents\Arduino\libraries\libmad-8266-master/AudioGenerator.h:40:22: error: 'AudioFileSource* AudioGenerator::file' is private

AudioFileSource *file;

janvanderborden
Posts: 588
Joined: 06.09.2014, 16:23
Location: Heiloo

Re: Mobile Rocmouse

Post by janvanderborden » 14.04.2018, 20:40

Hi Dagnall

problem solved, wrong library installed.

i go further trying getting the module working

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: Mobile Rocmouse

Post by Dagnall » 16.04.2018, 17:33

I have now got a proof of principle Rocnet Client general purpose wifi throttle working.
I have put the code on github. http://github.com/dagnall53/OctoThrottle
The code runs on a standard, very inexpensive, "wemos OLED battery Esp8266 board", which has everything needed already fitted.
I will post photos later, as the one I got sent first has an OLED issue and half the lines are missing...! (but I got half my money back).

The throttle gets a list of locos from rocrail using the lclist command and populates an internal memory array.
You can then select a loco by name and set it going to v-min, -mid, -cru, or -max.
It also allows you to command fn1-8 sounds.

In getting this working I found that the main limitation was that because Rocrail sends the LC list as a single complete message, the MQTT message gets bigger rapidly as locos are added. With the maximum memory allocated to the MQTT buffer and still having reasonably stable operation, (36000bytes), the code can only cope reliably with 8 locos. Any more and the MQTT message simply becomes too big and pubsubclient rejects it.
For this reason I called it OctoThrottle...

I plan to experiment more with making a ESP8266 Pi04 equivalent, so I can overcome the 8 loco limit, but I think this code may be useful even with the 8 loco limit.

(Rob, :?: Is there any way to send locolist items separately? - perhaps by having a command to send the "nth" item in a list? - this would overcome the size limitation)

Hope you enjoy this.
Dagnall

rjversluis
Site Admin
Posts: 41674
Joined: 10.04.2006, 08:48
Location: Speyer, Germany
Contact:

Re: Mobile Rocmouse

Post by rjversluis » 17.04.2018, 06:19

(Rob, :?: Is there any way to send locolist items separately? - perhaps by having a command to send the "nth" item in a list? - this would overcome the size limitation)
At the moment there is no way to do this, but a comparable implementation is made for sending the short IDs to the CS.
At a loco modify command a loco object broadcast its properties to the clients.

Maybe a Model command like "broadcastlocos"...

Post Reply

Return to “DIY Hardware”