Adding Wireless Connectivity to DCC++ Mega Base Station

LMSFan72 Jan 20, 2019

  1. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    OK, so I have it connected but I can't tell if anything is working!

    I have a spare I2C OLED that I would like to connect up so I can easily see what's going on like with DCCppESP32.

    Atani's development branch that I am using, https://github.com/atanisoft/BaseStation, only has code for LCD not OLED. Now, I am very much novice at writing code. Can I simply take the Config_OLED.h, Infoscreen.h, and Infoscreen_OLED_font.h and place them in the "include" folder and the InfoScreen.cpp file and put it in the "src" folder in my DCCpp_Uno folder. Then would i modify platformio.ini to call the lib_deps with ESP8266_SSD1306 added, and recompile?
     
  2. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Unfortunately no, that won't work... The easiest way to tell if things are working is connect to the serial console and send "<s>" to the base station and it should give you back an IP address somewhere in the output. You can then go to that IP in a browser and it should show you the throttle and base station status tabs.. I can look at adding OLED support on that branch but it won't be the same as the ESP32 side.
     
  3. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    OK, something is amiss! If I set COMM_INTERFACE to 0 or 1 and have nothing connected and look at the serial monitor I at least get the DCC++ boot up line. If I set COMM_INTERFACE to 4 I don't get that - again, nothing connected. Is there another config I need to find?
     
  4. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    after flashing the ESP8266, connect it to a serial line and lets test that it is able to connect to the AP... send these commands to test it:
    Code:
    <iESP-status>
    <iESP-scan>
    
    If it sees the AP then you can send:
    Code:
    <iESP-connect AP PASSWORD>
    
    And it should send back status packets until it either connects or fails. You can then send "<iESP-ip>" and it should give the IP of the ESP.

    When connected to the base station and you set the COMM_INTERFACE to 4 you should see on the base station Serial0 (USB) startup output. The ESP should be on Serial1 (for Mega), for the Uno you can specify pins in Config.h and it will use SoftwareSerial instead.

    Both Serial and WiFi should be active concurrently.
     
  5. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Well I got it on a serial line with nothing else connected and it appears to be continually resetting if I read this correctly - it just repeats:

    ets Jan 8 2013,rst cause:2, boot mode:(3,7)
    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v00000000
    ~ld
     
  6. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    looks like a bad flash maybe? you might need to adjust the platformio.ini file to match your board type, it was setup for an ESP-01 (ultra basic version of the esp8266) and also make sure you upload the filesystem.
     
  7. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Thanks Mike. Sorry, I appear to need an awful lot of help! I thought the same so I refreshed with the NodeMCU board as well as more generic ESP8266. Same result. I'm using the terminal to do it by:

    platformio init
    platformio run --target upload
    platformio run --target uploadfs

    Since I got the same result I then came out of VS Code and went to the native Arduino IDE and flashed it with a basic "Hello World" and then a simple wifi connection. Both of those worked. I wonder if I have missed something on the set up of Platformio, even though it reports flash success?
     
  8. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    I flashed it with a simple sketch via Platformio to connect to wifi and it worked fine. Reflashed it with the DCCppESP again and the same result as earlier. Stumped. Here's my build results:

    Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Verbose mode can be enabled via `-v, --verbose` option
    CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
    PLATFORM: Espressif 8266 (Stage) > NodeMCU 1.0 (ESP-12E Module)
    HARDWARE: ESP8266 80MHz 80KB RAM (4MB Flash)
    Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF MODES: FINDER(chain) COMPATIBILITY(soft)
    Collected 33 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- <ESP8266WiFi> 1.0
    |-- <ESP8266mDNS> 1.2
    | |-- <ESP8266WiFi> 1.0
    |-- <ArduinoOTA> 1.0
    | |-- <ESP8266WiFi> 1.0
    | |-- <ESP8266mDNS> 1.2
    | | |-- <ESP8266WiFi> 1.0
    |-- <ESPAsyncTCP> 1.2.0
    | |-- <ESP8266WiFi> 1.0
    |-- <ESP Async WebServer> 1.2.0
    | |-- <ESPAsyncTCP> 1.2.0
    | | |-- <ESP8266WiFi> 1.0
    | |-- <Hash> 1.0
    | |-- <ESP8266WiFi> 1.0
    | |-- <ArduinoJson> 5.13.4
    |-- <ArduinoJson> 5.13.4
    |-- <TaskScheduler> 3.0.2
    |-- <Hash> 1.0
    Linking .pioenvs\nodemcuv2\firmware.elf
    Retrieving maximum program size .pioenvs\nodemcuv2\firmware.elf
    Checking size .pioenvs\nodemcuv2\firmware.elf
    Memory Usage -> http://bit.ly/pio-memory-usage
    DATA: [==== ] 39.7% (used 32484 bytes from 81920 bytes)
    PROGRAM: [==== ] 42.4% (used 443060 bytes from 1044464 bytes)
    =================================================================== [SUCCESS] Took 10.45 seconds ===================================================================
    Terminal will be reused by tasks, press any key to close it.
     
  9. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    I can see from your compilation output that you are using the right board type, I was going to suggest that as a possible reason for the failure. Let's test a few things inside PIO (in VS:Code) and see if we can figure it out.

    First step, in platformio.ini change platform from the https://.... value to just "espressif8266". The board type setting of "nodemcuv2" appears to be correct for the ESP-12E. Here are steps to try within PIO to get a clean build/flash:

    On the left side bar, click the alien icon (Platform IO) and in the menu that comes up click the following options and allow them to complete before moving to the next:
    1. Clean
    2. Upload
    3. Upload File System Image
    4. Monitor
    At that point you should have a working ESP device and it should come after it starts up fully print out "<iESP-DCC++ init>" which indicates that it is done with startup and is ready to connect to an AP etc. If it doesn't come back with that string something else is going on and we would need to dig into it further.

    One benefit of PIO is rarely needing to use the commandline tools directly. But there are a few limitations, one being the monitor doesn't give you a way to send text to the device.
     
  10. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    OK, here goes...

    My platformio.ini already had just espressif8266 in there.

    1. Clean went OK
    2. Upload gave me one warning:

    Compiling .pioenvs\nodemcuv2\libe4d\ESP8266WiFi\ESP8266WiFiScan.cpp.o
    In file included from src\DCCpp_ESP.cpp:14:0:
    .piolibdeps\ESP Async WebServer_ID306\src/AsyncJson.h: In member function 'virtual void AsyncCallbackJsonWebHandler::handleBody(AsyncWebServerRequest*, uint8_t*, size_t, size_t, size_t)':
    .piolibdeps\ESP Async WebServer_ID306\src/AsyncJson.h:153:64: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) {
    ^
    Compiling .pioenvs\nodemcuv2\libe4d\ESP8266WiFi\WiFiClient.cpp.o

    3. Upload File System Image went OK
    4. I get garbage but I think that's because baud rate is 9600 - not sure how I change that. However, it repeats so I think it is still the same as before - I can go in and type platformio device monitor -b 115200 and I get the output from before still:

    ets Jan 8 2013,rst cause:2, boot mode:(3,7)
    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v00000000
    ~ld
     
  11. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    add "monitor_speed=115200" to your platformio.ini and you should be able to use the monitor with that speed by default.

    Let's see if it is even getting into the setup method, move these lines to here moving the SPIFFS.begin() line down to after the serial init. I'm wondering if maybe the SPIFFS piece is not starting up right.
     
  12. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    OK, here we are - we are getting exceptions after that:

    PS C:\Code\BaseStation-master\DCCpp_ESP> platformio device monitor -b 115200
    --- Miniterm on COM3 115200,8,N,1 ---
    --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
    ��N�␃␀<iESP-DCC++ init>
    Exception (28):
    epc1=0x40225010 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
    >>>stack>>>
    ctx: cont
    sp: 3ffffd70 end: 3fffffc0 offset: 01a0
    3fffff10: 00000010 3fffff70 3fffff70 3ffef77c
    3fffff20: 3fff3044 3fff302c 00000000 4020f0bb
    3fffff30: 00000a00 3ffe8694 3fffff70 4021d83c
    3fffff40: 4021ffb4 3ffe8694 3fffff70 3ffef92c
    3fffff50: 4021ffb4 3ffe8694 3ffef77c 4020f112
    3fffff60: 4021ffb4 4021ffc8 3ffef77c 40207e8c
    3fffff70: 3fff3044 0000000f 00000003 4021ffb4
    3fffff80: 3fff302c 0000000f 00000005 4021ff80
    3fffff90: feefeffe feefeffe feefeffe feefeffe
    3fffffa0: 3fffdad0 00000000 3ffef8f4 4021e394
    3fffffb0: feefeffe feefeffe 3ffe8580 401009c1
    <<<stack<<<
    ets Jan 8 2013,rst cause:2, boot mode:(3,7)
    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v00000000
    ~ld
    ␀<iESP-DCC++ init>
    Exception (28):
    epc1=0x40225010 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
    >>>stack>>>
    ctx: cont
    sp: 3ffffd70 end: 3fffffc0 offset: 01a0
    3fffff10: 00000010 3fffff70 3fffff70 3ffef77c
    3fffff20: 3fff3044 3fff302c 00000000 4020f0bb
    3fffff30: 00000a00 3ffe8694 3fffff70 4021d83c
    3fffff40: 4021ffb4 3ffe8694 3fffff70 3ffef92c
    3fffff50: 4021ffb4 3ffe8694 3ffef77c 4020f112
    3fffff60: 4021ffb4 4021ffc8 3ffef77c 40207e8c
    3fffff70: 3fff3044 0000000f 00000003 4021ffb4
    3fffff80: 3fff302c 0000000f 00000005 4021ff80
    3fffff90: feefeffe feefeffe feefeffe feefeffe
    3fffffa0: 3fffdad0 00000000 3ffef8f4 4021e394
    3fffffb0: feefeffe feefeffe 3ffe8580 401009c1
    <<<stack<<<

    output repeats..
     
  13. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    ok, we need to decode that trace. you can use this tool: https://github.com/littleyoda/EspStackTraceDecoder

    I've used that as: java -jar EspStackTraceDecoder.jar %USERPROFILE%\.platformio\packages\toolchain-xtensa32\bin\xtensa-esp32-elf-addr2line.exe .pioenvs\esp32\firmware.elf stack.txt

    you will need to adjust for the esp8266 paths but they should be similar to this.
     
  14. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Ok, another whole new learning experience! I’ll see if I get time tonight. Thank you
     
    Atani likes this.
  15. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Hi. I didn't know how to get it working in Platformio but was able to get something going in ArduinoIDE. This is what I got:

    Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
    PC: 0x40225010
    EXCVADDR: 0x00000000
     
  16. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    that is very weird, i'm not sure what it might be unfortunately.
     
  17. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    So, I did the only bit of debugging I know how - put serial print lines in after lines in the code to try and work out which line is doing it. I think it is this:

    MDNS.addService("dccpp", "tcp", 2560);
     
  18. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    I commented out this line and it now runs...

    I can send the status and scan commands and can see my AP. Using the
    <iESP-connect AP PASSWORD> command though will not connect... I get:

    <iESP connecting to >
    <iESP status 0>
    ....
    and eventually
    ...
    <iESP connect timeout>
     
  19. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    mDNS may be broken on the latest ESP8266 codeline, not sure though. Its fine to leave it commented.

    I gave you the wrong connect command, it should be <iESP-connect APLEN AP PASSWORD> where APLEN is the length of the AP name (spaces included if present). This was added at some point as a user had spaces in the AP name and I forgot it was there...
     
  20. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Could this be related to security on my router - how does it send these?? WPA, WEP, etc.....
     

Share This Page