TrippyLighting / EthernetBonjour

Bonjour Library for Arduino & Teensyduino
53 stars 46 forks source link

Compilation errors under 1.6.2 (and 1.0.5 r2) #2

Closed lathoub closed 8 years ago

lathoub commented 9 years ago

Thank you posting your library up on GitHub! I get compilation errors, both under 1.6.2 and 1.0.5 r2.

  1. error: 'IPAddress EthernetUDP::_remoteIP' is private
  2. error: 'uint16_t EthernetUDP::_remoteIP' is private
  3. error: 'class EthernetBonjourClass' has no member named 'beginMulti'
  4. error: 'uint8_t EthernetUDP::_sock' is private (used in constructor of EthernetBonjourClass)

1) easy to fix by replace _remoteIP with remoteIP() (already defined in EthernetUDP.h) 2) easy to fix by replace __remotePort with remotePort() (already defined in EthernetUDP.h)

3) I can not find any reference to beginMulti in EthernetBonjourClass nor any derived class in the std installation of the Arduino IDE. Some searching on the internet suggested a solution in http://forum.arduino.cc/index.php?topic=234340.0 After adding the code to EthernetUdp.h and EthernetUdp.cpp it all worked fine. Not sure you to pull to code out of EthernetUdp, i will look further into that.

4) _sock is indeed private in EthernetUDP (in EthernetUDP.h in 1.6.2. and 1.0.5 r2). Declaring EthernetBonjourClass as a friend class in somewhat radical just to access _sock. Removing the initialisation code (this->_sock = -1;) in the constructor of EthernetBonjourClass() does to affect output the examples (and removes the need to declare the friend class).

lathoub commented 9 years ago

Alternatively, declare _sock in EthernetUDP.h as protected, not private (line 45). This would be the only change in EthernetUDP.h (consider proposing this to the Arduino team) Then all the code from http://forum.arduino.cc/index.php?topic=234340.0 can be added to EthernetBonjourClass.cpp and .h

TrippyLighting commented 9 years ago

You are correct. There are changes necessary to EthernetUDP.h and EthernetUDP.cpp. I actually simply declared EthernetBonjourClass as a friend class in EthernetUDP.h and don't find that radical. YMMV ;-)

The post you have linked to is my post ;-) Have you been able to register and discover Bonjour services using the library ? I am interested in feedback. It works flawlessly for me but I almost exclusively use teens boards.

lathoub commented 9 years ago

Yes, it works fine for me (after the above changes), on a regular Arduino R3 and on a Mega (with ethernet shield). Thank you for contributing the code!

On the above suggestions, shall i make a pull request or do you prefer to make the changes? I have a slight preference to declare _sock to protected - so that EthernetUDP.h can be used in other projects (including the friend class prevents EthernetUDP.h from being used in another projects - but as you indicate, YMMV :-) - your call)

TrippyLighting commented 8 years ago

@lathoub I am in process of making the few updates necessary so this works with Arduino 1.6.6. Have you gotten this to work with the stock Arduino 1.6.6 Ethernet library ?

I can get this to work with the changes I described in my post on the Arduino forum referenced earlier in this thread. However, there are two lines of code right at the beginning of EthernetUDP.cpp in In EthernetUDP.cpp in beginMulticast(): [code] if (_sock != MAX_SOCK_NUM) return 0; [code/]

I have to out-comment these two lines in order to get a connection. However, these same two lines of code code work in the "normal" begin() routine. Any ideas ?

lathoub commented 8 years ago

I confirm that I see the same behavior, the initial test in beginMulticast() returns 0. I believe this is related to the initialization of this->_sock = -1; in the constructor of EthernetBonjourClass(). _sock is used prior to EthernetBonjourClass::begin(const char* bonjourName) and setting it again to -1 (255 as its un unsigned byte) messes up the (_sock != MAX_SOCK_NUM) test.

So removing the this->_sock = -1; in the constructor of EthernetBonjourClass() seems to solve the issue. Do you see the same results with the suggested fix?

Thanks

TrippyLighting commented 8 years ago

Yes, that is exactly what I was looking for. Thank you very much!

lathoub commented 8 years ago

I just noted that Arduino IDE 1.6.7 is out, you might directly want to compile and test against the latest IDE.Thanks!

lathoub commented 8 years ago

I just tested the 1.6.6 fix and works perfectly - thank you! (also under 1.6.7).

Can I suggest to include the library.properties file (as per https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification)? The content would look something like this:

name=EthernetBonjour 
version=1.0.0
author=TrippyLighting
maintainer=TrippyLighting <info@gkaindl.com>
sentence=Bonjour (ZeroConf) Library for Arduino & Teensyduino
paragraph=mDNS (registering services) and DNS-SD (service discovery) has been tested and works on: Teensy++2 with WIZ81MJ, Teensy3 with WIZ820io and Arduino with Ethernet shield
category=Communication
url=https://github.com/TrippyLighting/EthernetBonjour
architectures=*

The inclusion of the library.properties file (at same level as README.md) makes it easier to include the library in the Arduino IDE.

TrippyLighting commented 8 years ago

Thanks for the help. I'll do this over the holidays and will also provide a Keyword.txt file. I don't usually work with the Arduino IDE but with the Arduino Eclipse IDE/Plugin, which currently does not use the Keywords and library.properies file.