ESP8266 for remote sensors and points.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: ESP8266 for remote sensors and points.

Post by Dagnall » 15.06.2016, 19:53

Ok, when I implement EPROMs, I plan to put back your code for the multi bye commands,and I will put the addresses where you had them, but what I meant to say, was, is there any preferred locations for the servo settings, so that they can be read by the existing rocrail loconet servo programming page?

Cheers
Dagnall

Liviu M
Posts: 949
Joined: 03.12.2011, 20:44

Re: ESP8266 for remote sensors and points.

Post by Liviu M » 15.06.2016, 20:11

Hi,
I haven't done nothing special for servos, I should check it, but I think the (loconet) communication in the way I've implemented it should take care about all.
The EEPROM programming as I've implemented it, takes the EEPROM locations' addresses from the E5 messages - ucPeerRSvIndex.
If you look in the processXferMess() function, you will see that I'm using the first 3 (0..2) EEPROM location for the board ID/addresses:

Code: Select all

            if (ucPeerRSvIndex == 0) { //board address high
...
            } else if (ucPeerRSvIndex == 1) { //new low_address
...
            } else if (ucPeerRSvIndex == 2) { //new high_address

The "normal" 16 I/O take the next 48 locations (3 locations for each I/O):

Code: Select all

 } else if ((ucPeerRSvIndex < NR_OF_SVS) 
As I said, I should check it, but I think the servo info is (should be) stored in the same way starting with the address 100 or 101 - another 3-4 * 16 I/Os. The storing addresses are received during the E5 messages.
A trace snippet:

Code: Select all

20160615.210952.228 r0000B lnreader OLocoNet *trace dump( 0x06C9EE60: length=16 )
    offset:   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |ASCII...........|
    --------------------------------------------------------- |----------------|
    00000000: E5 10 50 51 01 00 01 65 00 02 00 01 00 00 00 6D |..PQ...e.......m|
20160615.210952.228 r9999I lnreader locoio   0108 evaluateLocoIOSV addr=80-1 sv=101 val=0 opc=write ver=0
20160615.210952.228 r9999c lnreader OLocoNet 1275 LocoIO SV response
20160615.210952.228 r9999I 06C9F700 OControl 1648 Program event 7: cv101=0 addr=80 type=2
Regards,
Liviu
Last edited by Liviu M on 26.06.2016, 09:28, edited 2 times in total.

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: ESP8266 for remote sensors and points.

Post by Dagnall » 15.06.2016, 20:14

Many thanks,
When I get back to this project that will be very helpful information..

D

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: ESP8266 for remote sensors and points.

Post by Dagnall » 18.06.2016, 19:41

I now have working code for a full SV controlled four servo, four sensor module.
The NodeMcu still has some spare pins, so other things might be added later.
The inputs have debounce code, and the servos turn off when not used to save power.

I have added notes in the code to help others modify the code.

This software sets up four servo ports starting at address (SV[2](hi), SV[1](lo).
These two SV[2] is reported at "sub" and SV[1] as "Low" in the Rocrail LocoIo General tab, and they can be modified from there.
Together they produce an "address" that Rocrail can send to:
With SV[2](1), SV[1](2), the first address of the Servos is 130 (Decimal).
This controls the Servo on Nodemcu ports D0 D1 ...
Port 1 is then address 130, (pin D0)
Port 2 is 131 and controls D1 ; port 3 is 132 and controls D2; port 4 is 133 and controls D3.
The Servo "speed" is set by "V" and this speed and the positions can be changed using the Rocrail LocoIO "servo" tab.
Speed "5" is fastest, "1" is slowest.
Servos turn off after reaching their positions (plus a short additional delay) to save power.

The module also has inputs that can send a B2 Message to rocrail.
The Messages these send are controlled by the SV's in (port1 ) SV's3,4 and 5 (then for Port2 Sv's6,7,8 etc..)
Using the Rocrail LocoIo programming tab for I/O, these can have their individual "address" set,
which will define what address is sent when the input port changes.
Port 1 uses pin D5, Port2 uses D6, Port 3 uses D7, Port 4 uses D9.

Using the following ports can or will cause issues and so they have been avoided in this module:
D4 is connected to the ESP8266 blue led on my boards.
D8 is used for serial data ?

Whilst I have tested with two NodeMcu simultaneously, and it works, the response to the "query" message with the code in the zip was not reliable with more than one device, so I added some delays that should make sure all devices report, but you may have to press query a few times..

The Blue Led on the ESP8266 flashes to indicate a message for that module has been received or sent. This can be useful to check if you have the right module address selected.

Only one thing now "bugs" me, the Rocrail LocoIO servo programming only allows 1-127 variables for the servo positions... ! But LocoIO (and my code) can read and write SV's up to 255. So I have to double the setting to allow full servo travel... Is there a setting to change this limit in Rocrail???
I note that the Modelspoorgroep Venlo LocoIO toolbox only allows settings from 1-100..(!). I would much prefer 1-180....

I expect that others may wish to have the IO port directions programmable, this should be possible, but is not something I needed right now.
You do not have the required permissions to view the files attached to this post.

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

Re: ESP8266 for remote sensors and points.

Post by rjversluis » 19.06.2016, 14:16

Only one thing now "bugs" me, the Rocrail LocoIO servo programming only allows 1-127 variables for the servo positions... !
This is for setting up existing LocoServo HW.
If Rocrail "bugs you"; Just write your own software. :mrgreen:

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

Re: ESP8266 for remote sensors and points.

Post by Dagnall » 19.06.2016, 17:19

No, I'm very happy with Rocrail. :beer:
Just surprised that the range was 1:127 ...

Dagnall

gramels
Posts: 221
Joined: 24.12.2009, 08:32
Location: around Zürich/ Switzerland and SouthWest Germany (Südbaden)

Re: ESP8266 for remote sensors and points.

Post by gramels » 05.12.2016, 16:11

Hi,

I struggle to set it up

what I get is

Code: Select all

192.168.100.191
Server started
Add hi :0 Add lo :89   
SV :98  is :0   SV :99  is :0   SV :100  is :0   
SV :101  is :0   SV :102  is :90   SV :103  is :1   
SV :104  is :0   SV :105  is :90   SV :106  is :1   
SV :107  is :0   SV :108  is :90   SV :109  is :1   
SV :110  is :0   SV :111  is :90   SV :112  is :1   
Board Base address for commands is:89 onwards 
 Will send sensor data from addresses :23 , 25 , 27 , 29 ,  
Ports set
Servo on D-1 requests state:1 will be set to position :0 at speed '0'  {NOTE: 2 deg steps, so Range[1..90] = 2 to 180 degrees}
Servo on D0 requests state:1 will be set to position :0 at speed '1'  {NOTE: 2 deg steps, so Range[1..90] = 2 to 180 degrees}
Servo on D1 requests state:1 will be set to position :0 at speed '1'  {NOTE: 2 deg steps, so Range[1..90] = 2 to 180 degrees}
Servo on D2 requests state:1 will be set to position :0 at speed '1'  {NOTE: 2 deg steps, so Range[1..90] = 2 to 180 degrees}
Servo on D3 requests state:1 will be set to position :0 at speed '1'  {NOTE: 2 deg steps, so Range[1..90] = 2 to 180 degrees}
Change on IO port : 1  detected = Sensor Address(: 23)   B2 0B 40 06
Change on IO port : 2  detected = Sensor Address(: 25)   B2 0C 40 01
Change on IO port : 3  detected = Sensor Address(: 27)   B2 0D 40 00
Change on IO port : 4  detected = Sensor Address(: 29)   B2 0E 40 03

This Message is for:0 We are:89 (addrHi, SV[2]:0  addrLo, SV[1]:89  Full Message is: 00 00 00 00 01 07 02 08 00 00 0B 05 10 09 00 01
This Message is for:0 We are:89 (addrHi, SV[2]:0  addrLo, SV[1]:89  Full Message is: 00 00 00 00 01 07 02 08 00 00 0B 05 10 0A 00 01
what do I miss?

Dagnall
Posts: 278
Joined: 15.05.2015, 14:41

[closed] ESP8266 for remote sensors and points.

Post by Dagnall » 05.12.2016, 17:54

Which version are you running?
(Sorry.... I should be more careful with adding version numbers...it is a "work in progress")

From what i see, that looks like an older version, before I changed to the MQTT interface ?.....
If so, and if I remember the code (Sorry!) it is telling you it is address 192.168.100.191, and that it will respond to RocRail code 0:89, and addresses 23,25,27 and 29..
You sent two commands to the "all stations" ADDRESS O "0".

HOWEVER, My experience with this version of the code was that it was possible to get drop outs more often than I wanted, so I moved to the "MQTT" based version.
I started a new topic "ESP8266 MQTT Client" http://forum.rocrail.net/viewtopic.php?f=90&t=12504

The MQTT approach requires that you add another bit of software to your PC, the "MQTT broker", but is much better behaved.
The main complication is that the MQTT broker approach needs the ESP8266 to know the IP address of the MQTT broker, My code expects this to be in the range xxx.xxx.xxx.1 to xxx.xxx.xxx.50 and automatically tries to find it if does not connect after ten attempts (It saves the last known good broker address in eeprom saved data).
The new code also uses "WiFI manager", so it automatically starts an AP and HTML page for you to select and set your AP and Password if it cannot connect to your router..

I put this code, with instructions, in https://github.com/dagnall53/ESPWIFIROCNET

Cheers
Dagnall

Post Reply

Return to “DIY Hardware”