DCC++ BaseStation with WiFi (ESP)

Atani Feb 11, 2017

  1. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    I have uploaded my initial revision of the DCC++ BaseStation with an ESP8266 module acting as the primary interface for the base station.

    You can download it from https://github.com/atanisoft/BaseStation.

    Currently this supports connecting to a WiFi AP, starting a server on the ESP serving up a two cab throttle (based on http://trainelectronics.com/WiFi-esp8266/Setup/) and a JMRI listener. I plan on adding a WiThrottle listener as well as exposing additional DCC++ features via the ESP server.
     
  2. KC Smith

    KC Smith TrainBoard Member

    102
    102
    10
    Mike,

    Thanks for taking on and enhancing this DCC++ BaseStation with an ESP8266 module project. It looks well documented.

    Question,

    in DCCPP_Uno.h
    Line 85 #elif MOTOR_SHIELD_TYPE == 1
    Should this be #elif MOTOR_SHIELD_TYPE == 2

    As defined in Config.h
    Line 16 2 = BTS7960B (MAX 27V/43A PER CHANNEL)

    Sorry if I'm misreading this ..

    Looking forward to seeing progress in this endeavor.

    Kevin
     
    Scott Eric Catalano likes this.
  3. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    You are quite likely correct on this. I had started on integrating support for the BTS7960B motor boards as I plan on using them and it got carried along for the ride with the ESP stuff in the commit. I will take a closer look at this section and clean this up a bit further. [edit] I took a quick look and you are very correct! Thanks!

    Your welcome. I couldn't have gotten this far on it without the help of others though, especially UK_Steve. He wrote a lot of the support through multiple posts on this forum and I took them and cobbled together a decent module binary. I have a few more plans for the ESP side including WiThrottle support (Thanks to TwinDad for his work in this area!). I also plan on exposing a lot more of the DCC++ base station via the web interface including (but not limited to): ability to define turnouts and sensors, turn on/off track power, programming track interface (using WebSocket).

    Long term goal would be limited need for JMRI (its a great tool for sure but not convenient for all usages). I will still use JMRI's DecoderPro interface but I wasn't planning on using much beyond that originally.
     
    Last edited: Feb 12, 2017
  4. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    Since I originally posted this I have been tweaking the UI and usage of the ESP a bit to extend the functionality further. I now have a version of UK Steve's latest throttle UI working on the desktop and at least my OnePlus X mobile with success. Here are some screenshots of the new UI:

    "Status" tab: https://goo.gl/photos/X1QwkvnbWCZJnNYx6
    "Serial Monitor" tab: https://goo.gl/photos/NzgkEBXpqEb5y1Kf7
    "Throttle" tab:
    #1: https://goo.gl/photos/8bYxspzsq3oV27Tu6
    #2: https://goo.gl/photos/sTecvbs2p3DQqnvQ8
    When the display height is over 775px you can control up to 10 locomotives from the one throttle.

    And here is a shot of the board that I will be placing near the top of my helix with the various connects (5VDC top left, serial IO bottom left, 3.3VDC bottom center):

    https://goo.gl/photos/9tWxw1mmfPobYc7d6
     
  5. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    I am taking a giant leap here, and trying the ESP version. never used ESP before, so please consider me dumb (sort of ;) ).
    I have an ESP8266-01, best as i can tell. i am trying to upload to the ESP via a shield from eBay that has the logic conversion built in, as well as the buttons for ESP reset, and GPIO0. it is plugged into an arduino UNO board with the Arduino chip removed (acting as a USB to serial converter).

    Now, assuming i understand what i don't understand, the sketch for the "DCCpp_ESP" is uploaded to the ESP? and the other sketch is uploaded to the DCC++ base station? i get compile errors from the ESP sketch:
    Code:
    C:\Users\Travis\Downloads\BaseStation-atani\BaseStation-master\DCCpp_ESP\DCCpp_ESP.ino: In function 'void loop()':
    
    DCCpp_ESP:363: error: 'class AsyncWebServer' has no member named 'end'
    
          webServer.end();
    
                    ^
    
    what have i done that i shouldn't have? ;)

    ~Travis
     
    Scott Eric Catalano likes this.
  6. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    It looks like you are missing a couple libraries:
    These are required for the ESP side. I have tested it quite extensively with the ESP-01. I will be pushing an update soon with an updated html interface and a few bug fixes for the base station related to broadcasting the incoming/outgoing messages to all interfaces.

    One thing that I observed but have not debugged fully was JMRI failing to parse the <s> output correctly from time to time. The last > gets dropped but only on the ESP side.
     
  7. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    I have them...
    [​IMG]
    ~Travis
     
    Scott Eric Catalano likes this.
  8. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    Are they present in the Arduino IDE's library folder? I will be moving to including them in my repo soon since they are a bit of a maintenance issue for Arduino Eclipse as they are not present by default there either..
     
    Scott Eric Catalano likes this.
  9. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Code:
    C:\Users\Travis\Downloads\BaseStation-atani\BaseStation-master\DCCpp_ESP\DCCpp_ESP.ino: In function 'void loop()': DCCpp_ESP:363: error: 'class AsyncWebServer' has no member named 'end' webServer.end();
    Come on guys, the IDE points you right to the problem here.

    On line 363 of DCCpp_ESP.ino in function 'void loop().....

    webServer.end() is basically a invalid instruction.

    Looking through the library code, I can find no reference either.

    Maybe in the authors last updates, it got changed to webServer.reset() which is valid, so try that:)
     
    Scott Eric Catalano and esfeld like this.
  10. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    Yes they are.

    ok got past that, now:

    Code:
    C:\Users\Travis\Documents\Backup\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp: In function 'void wifi_wps_status_cb(wps_cb_status)':
    
    C:\Users\Travis\Documents\Backup\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp:593:14: error: 'WPS_CB_ST_UNK' was not declared in this scope
    
             case WPS_CB_ST_UNK:
    
                  ^
    perhaps if i had a copy of the libraries you have, that the code was tested with. i think they may have done some updates since you downloaded the libraries, and in effect, they "broke" what worked. ;)

    ~Travis
     
    Scott Eric Catalano likes this.
  11. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    Yeah, they broke it on the tip of master. the commit I am on is this one: https://github.com/me-no-dev/ESPAsyncWebServer/archive/bab5457584f2c0acd56e0772be19bf48501356a6.zip and for ESPAsyncTCP it is: https://github.com/me-no-dev/ESPAsyncTCP/archive/36b6b5ad325c029be466a223568e6f74894f6834.zip

    I did a quick look at the code and I don't see anything indicating that they broke this. Here is the method declaration and body:
    In WebServer.cpp:
    Code:
    void AsyncWebServer::end(){
      _server.end();
    }
    
    In ESPAsyncWebServer.h:
    Code:
    void end();
    
    In both cases add these snippets immediately after the declaration/body for begin()

    I will also include these edits in the next commit so they are present with the libraries included by default!
     
    Scott Eric Catalano likes this.
  12. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Travis, yeah your later error is also a difference in the library versions

    ESP8266WiFiSTA.cpp:593:14: error: 'WPS_CB_ST_UNK' was not declared in this scope

    case WPS_CB_ST_UNK:

    In the version I have that function looks like this...

    BTW the best source of the working versions is via the Git install method described in the repo readme.

    The Arduino boards manager method is not the best route at all:(

    Code:
    void wifi_wps_status_cb(wps_cb_status status) {
        DEBUGV("wps cb status: %d\r\n", status);
        switch(status) {
            case WPS_CB_ST_SUCCESS:
                if(!wifi_wps_disable()) {
                    DEBUGV("wps disable failed\n");
                }
                wifi_station_connect();
                break;
            case WPS_CB_ST_FAILED:
                DEBUGV("wps FAILED\n");
                break;
            case WPS_CB_ST_TIMEOUT:
                DEBUGV("wps TIMEOUT\n");
                break;
            case WPS_CB_ST_WEP:
                DEBUGV("wps WEP\n");
                break;
        }
        // TODO user function to get status
    
        esp_schedule(); // resume the beginWPSConfig function
    }
     
    Scott Eric Catalano likes this.
  13. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    yeah, even with a few patches, i keep getting more errors. i'm gonna clean out my ESP stuff and start over using the ReadMe method. hopefully that will work better...

    ~Travis
     
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    Scott Eric Catalano likes this.
  15. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    ok, back to the "webServer.end()" issue...
    I am starting to detect a pattern here ;)

    ...patching the files... test compile... OMG! it compiled! :)

    now i just have to upload it...
    can't seem to upload using my ESP shield. i may have to build a programmer, as my chip-less UNO board doesn't seem to be working for some reason.

    ~Travis
     
    Scott Eric Catalano likes this.
  16. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
  17. Atani

    Atani TrainBoard Member

    1,336
    1,038
    28
    For upload to the ESP, did you short GPIO0 to GND?
    [​IMG]
    I have a small breadboard adapter for this and short GPIO0 to GND and RST to GND briefly to reset the board. It should then respond to uploading from the PC via FTDI cable or other RX/TX connection. After upload I disconnect GPIO0 from GND and either short RST or disconnect/reconnect VCC.

    Also be sure to short CH_PD to VCC.
     
    Scott Eric Catalano likes this.
  18. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    i did just that, though with the shield, i am unsure if CH_PD is tied anywhere. i will have to check it tomorrow as my brain is fried for tonight.

    Thanks for your help thus far :D

    ~Travis
     
    Scott Eric Catalano likes this.
  19. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    this is what i get when i try to upload:
    Code:
    warning: espcomm_send_command: wrong direction/command: 0x01 0x00, expected 0x01 0x08
    warning: espcomm_send_command: wrong direction/command: 0x01 0x00, expected 0x01 0x08
    warning: espcomm_send_command: wrong direction/command: 0x01 0x00, expected 0x01 0x08
    warning: espcomm_send_command: wrong direction/command: 0x01 0x00, expected 0x01 0x08
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    error: espcomm_upload_mem failed
    perhaps i have the settings wrong somewhere...

    ~Travis
     
    Scott Eric Catalano likes this.
  20. Travis Farmer

    Travis Farmer TrainBoard Member

    345
    314
    12
    we have upload! :D
    I had to use a FT232 adapter, rather than a headless UNO.
    i hit reset with a comm terminal open, and the last bit of data was "<iESP-DCC++ init>", so it seems to be ready. i have only to upload the Arduino portion to my DCC++ board, or any handy MEGA2560 for that matter, to test it.

    ~Travis
     
    Scott Eric Catalano likes this.

Share This Page