Ethernet Gateway on Arduino Yún



  • I'm trying to port the Ethernet Gateway sketch to an Arduino Yún using the Bridge library which connects the Yún to the on-board Linux processor (which will be running my controller.)

    I've prototyped a stand-alone server which works well, so I know how to use the gateway. The port seems as though it should be straight-forward:

    • no need to provide IP or MAC address, since this is handled on the Linux side
    • EthernetServer --> YunServer
    • EthernetClient --> YunClient
    • Ethernet.begin() --> Bridge.begin()
    • server.available() --> server.accept()

    However...

    I get a type conversion error at compile time on this line:

    void output(const char *fmt, ... ) {
       va_list args;
       va_start (args, fmt );
       vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
       va_end (args);
       Serial.print(serialBuffer);
       server.write(serialBuffer);  // <-- ERROR HERE
    }
    
    

    with this diagnostic

    Arduino: 1.7.6 (Mac OS X), Board: "Arduino Yún"
    
    YunMSGateway.ino: In function 'void output(const char*, ...)':
    YunMSGateway.ino:143:29: error: invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    In file included from YunMSGateway.ino:83:0:
    /Users/akbooer/Documents/Arduino/Arduino 1.7.6.app/Contents/Java/libraries/Bridge/src/YunServer.h:35:20: error:   initializing argument 1 of 'virtual size_t YunServer::write(uint8_t)' [-fpermissive]
         virtual size_t write(uint8_t c);
                        ^
    Error compiling.
    

    So I guess the question is, simply, how do I coerce from char* to uint8_t ?

    I know next to nothing about C or C++, but I have tried the simple (uint8_t) prefix with similar errors. I'm sure this is trivial and (hopefully) the only thing standing between me and a fully functioning Ethernet Gateway on the Yún.

    Any help much appreciated.


  • Contest Winner

    Generally you cannot. The types are not interchangeable.
    You try to pass a string buffer to a function that only accept a single character.
    You could try (assuming serialBuffer is a NULL-terminated string) this:

    void output(const char *fmt, ... ) {
        ...
        Serial.print(serialBuffer);
        for (int i = 0; serialBuffer[i] != '\0'; i++) {
            server.write((uint8_t)serialBuffer[i]);
        }
    }
    

    It could also be that server.write expects to also get the NULL byte in which case you also have to pass the that one like this:

    void output(const char *fmt, ... ) {
        ...
        Serial.print(serialBuffer);
        for (int i = 0; serialBuffer[i] != '\0'; i++) {
            server.write((uint8_t)serialBuffer[i]);
        }
        server.write((uint8_t)serialBuffer[i]);
    }
    


  • Ah, well, thank you for that anyway.

    Maybe it was the wrong question, but I hope to have solved the problem by discovering another server method 'print', which takes the right argument type. (A little knowledge is a dangerous thing.)



  • Wondering, now, how to wire up the NRF module to the Yún. I'm following the Ethernet Gateway guide at http://www.mysensors.org/build/ethernet_gateway, but, of course, the pin configuration is different from that shown.

    Am I right in assuming that I use the pins on the ICSP for SCK, MISO, and MOSI, then digital pins 5 and 6 for CE and CSN?

    Also supposing that there's no need for software SPI in this case?

    Advice most welcome! Thanks in advance.



  • Success! I now have a functioning Ethernet Gateway running on a Yún using the Bridge library which connects the Arduino Yún to the on-board Linux processor.

    The software changes are broadly those outlined here in an earlier post. I am more than happy to put this up on GitHub if someone can advise the best way / place for this (ie. should it be a a new file, say YunEthernet, or a conditional compilation of the main gateway, or what?)

    It works with hardware SPI and again the wiring is as described previously (with earlier doubts now dispelled.)

    There's two possible configurations:

    • as a 'normal' gateway, addressable from the LAN (with the IP handing all done on the Linux processor)
    • as a 'private' gateway, only addressable from the local host processor (as a controller)

    The latter of the above options is the way I am currently running this, otherwise there's little point in using a Yún at all, with my own 'openLuup' Vera emulator running on the Linux processor using the standard Arduino plugin to link to the gateway.

    I don't know about the speed of the Arduino/Linux bridge (it is reported elsewhere as being notoriously slow) but it seems very adequate for the job I am currently using it for (perhaps not a very heavy network load.)



  • Just to put a footnote to the above (copied from another post - apologies, but it does belong here) ...

    GitHub fork with the Yun Gateway

    https://github.com/akbooer/Arduino/tree/development/libraries/MySensors/examples/GatewayYun


  • Hardware Contributor

    @akbooer: hi.
    I hope to have some time to test your very interesting work 😃
    I have a dragino he, maybe I will hook a moteino mega.
    I have ordered this one too:
    http://www.seeedstudio.com/depot/LinkIt-Smart-7688-Duo-p-2574.html
    Same price as dragino but there is 32u4 onboard 😃
    what do you think about it? I am very curious, plus it seems a little bit more powerful, but not the same chip.



  • That's a really good price! A whole lot better than a Yún. I've not tried a Dragino but they seem to offer similar functionalities. I'm not sure about the details of the serial link handling for the bridge - if the bridge library has the same calls, it should work OK.


  • Hardware Contributor

    thx for reply 😄
    yes dragino HE works like yun I think.
    for linkit as the product seems new, there is a little bit less docs. but I will see, price was so interesting that it was too much tempting lol.
    I will tell you what I can get...
    for fun, I have not presented yet, but I have a board in progress for raildin : 8x relays + 8inputs for yun and I added ethernet connector+hub usb chip



Suggested Topics

  • 1
  • 10
  • 7
  • 3
  • 5
  • 17
  • 1
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts