ESP8266 for remote sensors and points.

Moderator: Moderators

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 05.06.2016, 14:56

Livius, many thanks for your patience so far. !

Can I just check all the steps that you do (and responses you see) to confirm communications are working?
What I do is this:
    Run Rocrail, check in rocrail properties the "controller" tab that the LocoNet controller is there,properties are: Interface ID "loco" set to Lnudp Hostname 224.0.0.1, and port 1235 CTS Flow unchecked GBM16xn unchecked.
    Check ESP code in arduinio: changed your defaults for IPAddress ipServer(192,168,0,5); (address of this PC that is running rocrail)
    Check ESP via the webserver: it says 192.168.0.22, BA=88 SA =1648 (I have changed them via the webserver and they stay "changed..."
    Then, In Rocrail, click programming>loconet> locoio>addresses "query".. and I get "locoIO SV response" in controller window and "timeout on reply... in the server window.
    next, try click programming>loconet> locoio>General, set IID="loco" (the name of loconet on this rocrail ) set "low" to 88 "sub" to 1 ; press Get.... and I get "locoIO SV response in Controller and "timeout on reply... in the server window.
    still nothing happening on the ESP serial monitor ... ( should there have been anything?)
    Repeat with "Low" = 75 (or anything...) and I still get "locoIO SV response", and timeout on reply.

I next turned off windows firewall for both public and local... and quickly repeated the steps above, I got the same responses (or lack of.. in rocrail) , so switched the firewall back on....(and breathed again)

NEXT.. I noticed that the Comms monitor has "add 1; aid1; Station:24:e3:14:92:54:9c join, AID = 1" (this 24:e3 etc does not seem to match anything I can see when I "IPCONFIG / All") see picture...

SO.. I disconnected the broadband cable from router....Turned off windows firewall for private and public networks.
AND extensively repeated the above tests.. including changing Sub to 102 and sub to 88, (is this what the ESP means when it says address 102-88"?)... but I cannot repeatably get the "add1 .. etc message in the comms monitor.

I had been expecting some responses from the Query command, what I need to start is a repeatable sequence that give some confidence that the ESP is connecting.
How do you test yours?

All the best
Dagnall
You do not have the required permissions to view the files attached to this post.
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 15:26

Hi Dagnall,

- on the PC running the Rocrail, in the CS properties add also the server's own ip address in the Local IP field (in your case probably 192.168.0.5)
- when querying after boards, in the General tab fill only the IID (with "loco"), leave all other at the default values. Change to Addresses tab and start a query. Your board address should apear.
- after issuing a Query on Rocrail, with the last version of the software from git the Arduino monitor window should indicate the receiving/sending some Loconet messages, like in the attached screenshot. The same messages appear in the server's terminal (the second screenshot).
- the ipServer in sketch is not used, is defined for some tests, but inactive. You can remove (comment it out) it and the sketch should still work.

If nothing else works, try to erase the whole flash in your ESP and reflash the sketch on a "fresh" state.

Regards,
Liviu
You do not have the required permissions to view the files attached to this post.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 05.06.2016, 15:33

just trying this.. quick question: How did you get board address "1-89" ? mine came up 102-81 and I changed it to 88, but cannot change the 102...
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 15:38

As i said, try to erase your ESP, it seems there is some garbage in it.
A fresh board will be initialized with 89-1:
Code: Select all
#define BOARD_ADDR_LO   89
#define BOARD_ADDR_HI   1
...
    EEPROM.begin(256);
       
    ucBoardAddrHi = EEPROM.read(ADDR_NODE_ID_H); //board address high
    ucBoardAddrLo = EEPROM.read(ADDR_NODE_ID_L); //board address low

    if((ucBoardAddrHi == 0xFF) && (ucBoardAddrLo == 0xFF)){ //eeprom empty, first run
       ucBoardAddrHi = BOARD_ADDR_HI;
       ucBoardAddrLo = BOARD_ADDR_LO;

       EEPROM.write(ADDR_NODE_ID_H, ucBoardAddrHi );
       EEPROM.write(ADDR_NODE_ID_L, ucBoardAddrLo);
 
       ucSenType=0x0F;
       EEPROM.write(ADDR_USER_BASE+2, 0);
       EEPROM.write(ADDR_USER_BASE+1, 0);
       EEPROM.write(ADDR_USER_BASE, ucSenType);

       EEPROM.commit();
    } //if((ucBoardAddrHi == 0xFF)

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

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 15:44

Because at reusing the ESP can happens that the EEPROM contains some data, I suppose I should include an EEPROM check, like the one I've implemented for the rfid2ln board.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 05.06.2016, 15:52

So my esp eeprom has data that is not erased when i re-flash the program... I had not realised that.

I DID reprogram with another sketch entirely and checked that program worked, but presumably the EEprom was not altered by that...
I cannot find anything obvious in the arduino IDE to clear the EEprom..
......Some visitors have arrived, so I must stop, but if you could direct me to something that will clear out the EEProm, that would be most helpful!!

Dagnall
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 15:56

Not sure if it real works (it happens very fast :), to be sure I'm waiting few seconds after it finishes), but I was using the esptool.py:
Code: Select all
esptool.py --port /dev/ttyUSB0 erase_flash
,
where /dev/ttyUSB0 is my serial port under Linux, you should change it.
Last edited by Liviu M on 05.06.2016, 16:03, edited 1 time in total.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 16:01

Or you force writing the initial parameters - you comment out the check (and its closing bracket)
Code: Select all
//    if((ucBoardAddrHi == 0xFF) && (ucBoardAddrLo == 0xFF)){ //eeprom empty, first run
...
//    } //if((ucBoardAddrHi == 0xFF)

reprogram the board, and reactivate the check.

Code: Select all
    if((ucBoardAddrHi == 0xFF) && (ucBoardAddrLo == 0xFF)){ //eeprom empty, first run
...
    } //if((ucBoardAddrHi == 0xFF)
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 05.06.2016, 19:35

Friends gone, gardening completed, Time to play..

I used the "modify the code version" to clean the eeprom.. and now get "1-89 and sensor addr :1", so I am getting a lot further:
the Comms monitor gives a response now :) :) :) when I "query", but the Rocrail code window does not show the same matching information as yours :cry: ,
It looks like you have some trace dump option set??? Anyway mine gives a different response, (see image after I had pressed query once...)

It then repeats the line ending ... 0147 makereqLNSV addr=0-0 sv=0 val=0 . every time I press query.
and I get the same stuff in the comms monitor...
I can leave out the "loco" in the general tab and still get these responses ( at least with this test rocrail plan that does not have canbus so things are obviously talking...

I will keep playing quietly and hopefully can start to sort this out.. (but any help and suggestions would be appreciated!)

When you next update or modify the code, can I suggest/ask that you add a "clean EEPROM" button on the web server? It might be helpful to others following this route in the future!.
I will probably not add one to my local copy of the code now, just in case there are any other changes or improvements you plan to make, so that I can keep in sync!..

Cheers and thanks again for the assistance.
Dagnall
You do not have the required permissions to view the files attached to this post.
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 20:27

Hi,
good news.
The different server messages are because I use the byte level traces (in Rocview -> File -> Rocrail Properties -> Trace tab), but once it is working you don't need it.
Now, if the board address appears in the Addresses tab of the LocoIO programming menu, you can follow my documentation I earlier posted (for rfid2ln interface) to read & program the board & sensor addresses.
From now on, to define new functionality to the interface, you are more or less alone. Just check the "Loconet personal edition" document and try to implement the messages for sensors. If you want to keep the compatibility with the Rocrail, you should study the LocoIO documentation also.

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

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 05.06.2016, 20:41

Ah, yes, when I turn the trace on, I do see the same sort of responses..
:beer:

As you say, now I must modify the code.. I will come back to the forum when I get something working.. But at least I know the wifi is talking to rocrail... Now to try to understand Loconet!

Many thanks
Dagnall
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 05.06.2016, 21:30

Actually, if you plan to emulate the LocoIO *) (as I've done in all of my projects), the things are half done.
In the actual sketch, all the programming part is already implemented. You need "just" to "connect" the ESP8266's pins with the location in the memory (EEPROM) I've already used to save the addresses, and implement the right messages to handle the events.

*) Study of the LocoIO is mandatory to understand how it works. In few words, each I/O (ESP pin) have three configuration bytes (EEPROM locations), one for the pin type (in/out...) and two for address (or 6 bytes if you want to have PWM outputs).

Regards,
Liviu

PS I'll follow your progress. :)
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Dagnall » 06.06.2016, 23:21

I have a sketch that now moves a servo when a rocrail switch is set straight or thrown. :D

It checks and uses the "PORT" variable in the Loconet interface to select which "board" the ESP is set to respond to:
I have noted that in loconet, there are 11 bits of address [A0-A10], and I can now set and save all 11 in the HTML settings, ( Some bugs, I only check 10 bits in this version, will set that right tomorrow, and try to find why it sets the wrong value on initial setup... works fine after being changing the address )
But in Rocrail, it appears that you can set the "port" setting in the switch interface to anything , the loconet interface correctly seems only able to send 11 bits ? Presumably the rocrail loconet interface does not have any validity checks at that point??

I am now working on trying to get the "E5" code working.. the checks you seem to have for Address do not seem to match what I can find in http://www.digitrax.com/static/apps/cms/media/documents/loconet/loconetpersonaledition.pdf
was the code experimental, or did you get this part from someone else, and have you tested it to check it works correctly?

I have been looking at all the other LOCONET LocoIO messages sent from the rocrail programmer, and they all seem to use the E5 peer to peer command.. But I am having difficulty seeing how or if t works correctly..

Any hints would be appreciated, if the code is experimental, then I can understand why it does not seem to match the digitrix document.....

All the best

Dagnall
Last edited by Dagnall on 07.06.2016, 13:05, edited 1 time in total.
Dagnall
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 07.06.2016, 06:15

I'll put a detailed answer later in the afternoon. Till than, just an advice - to understand how the Rocrail's messages are build, look in the LocoIO documentation..

Regards,
Liviu

PS The E5 messages between Rocrail and ESP should just work. In the ESP sketch there are also "address conversion formulas".
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: ESP8266 for remote sensors and points.

Postby Liviu M » 07.06.2016, 18:25

Hi,

as I said, the programming communication Rocrail <-> rfid2wifi (the E5 messages) are already (full) implemented in the processXferMess() function. You should probably change
1. the number of addresses "allowed" (nr. of active ports * 3) - remove the if in
Code: Select all
           } else if ((ucPeerRSvIndex < NR_OF_SVS) /*||

(remains probably only
Code: Select all
           } else {

2. Reactivate the write of the "port type locations" => remove the line
Code: Select all
               if ((ucPeerRSvIndex % 3) != 0) { // do not change the type (leave it as IN)

That was for the programming messages. The conversions - LocoIO H+L addresses <-> real (full) address <-> Loconet format addresses are also implemented:
1. LocoIO addresses (save unchanged in eeprom) -> full address conversion:
Code: Select all
           uiAddrSenFull = 256 * (EEPROM.read(ADDR_USER_BASE+2) & 0x0F) + 2 * EEPROM.read(ADDR_USER_BASE + 1) +
                           ((EEPROM.read(ADDR_USER_BASE+2) & 0x20) >> 5) + 1;

2. Full address -> Loconet reporting -> function calcAddrBytes().
You should probably implement the conversion Loconet -> full address.

You should, however, implement the "functional" communication.
For sensor reports you should detect the inputs changes, build and send the corresponding OPC_INPUT_REP (0xB2) messages using the addresses saved in eeprom for the changed port (converted to the right format). You can look in the rfid reporting code, it is mainly the same procedure with other opcode, data, length.
And maybe you should detect and answer the sensor query message.

For switches you should detect the OPC_SW_REQ (0xB0) messages sent to addresses on your boards, decode them and switch the needed ports accordingly.

I hope that after reading the documents mentioned above the things will be more clear.

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

PreviousNext

Return to DIY Hardware