Hi.
My T3.6 with WIZ820io using the adaptor plate works perfectly on DHCP and static ip. I want to add Bonjour support and installed this library (https://github.com/TrippyLighting/EthernetBonjour) which installs and compiles successfully.
it reads the MAC address correctly and also I can ping the DHCP-assigned IP. As soon as the code uses Bonjour things get mixed up.
EthernetBonjour.begin("arduino");
is ok - however I can't resolve arduino.local on my mac.
2nd line:
int res = EthernetBonjour.addServiceRecord("test._http",
80,
MDNSServiceTCP, NULL);
works sometimes. after unplugging the Teensy it always continues and res = 1 which means success. Sometimes it hangs/crashes inside this method. When I use:
int res = EthernetBonjour.addServiceRecord("test._http",
80,
MDNSServiceTCP);
without the TXT record, it crashes way more often.
The NULL thing is something I came up with by looking at the library code:
No matter what I do, when having a good spin (no crashes) the loop() get's executed I can see the webserver page using the ip address but the Teensy will never register it's hostname nor any Bonjour service records (using OSX Bonjour Browser application I can see a lot of Bonjour services of other devices in my LAN but never my arduino).
In addition none of the example sketches bundled with the library works correctly. My network seems to be OK, I tried different routers - no luck.
I tried for hours but couldn't narrow it down so far. I would like to ask:
- my WIZ820 works basically. But multicast doesn't seem to work. Is this a known limitation?
- is this library (which I think it's the newest I've found and is built on EthernetUDP rather than direct HW calls to w5100) compatible with the T3.6? Which library is a good one to test?
- are there any differences between a Teensy 3.0 to Teensy 3.6 in regards to this? Could it be that this library simply won't work on a 3.6 but would work fine on 3.0/3.1/3.2?
- Are there any plans to include Bonjour in the Teensy library of Ethernet?
- any pointer on how to troubleshoot this?
any help would be very much appreciated! thanks!!!!
This is my code:
My T3.6 with WIZ820io using the adaptor plate works perfectly on DHCP and static ip. I want to add Bonjour support and installed this library (https://github.com/TrippyLighting/EthernetBonjour) which installs and compiles successfully.
it reads the MAC address correctly and also I can ping the DHCP-assigned IP. As soon as the code uses Bonjour things get mixed up.
EthernetBonjour.begin("arduino");
is ok - however I can't resolve arduino.local on my mac.
2nd line:
int res = EthernetBonjour.addServiceRecord("test._http",
80,
MDNSServiceTCP, NULL);
works sometimes. after unplugging the Teensy it always continues and res = 1 which means success. Sometimes it hangs/crashes inside this method. When I use:
int res = EthernetBonjour.addServiceRecord("test._http",
80,
MDNSServiceTCP);
without the TXT record, it crashes way more often.
The NULL thing is something I came up with by looking at the library code:
Code:
// return values:
// 1 on success
// 0 otherwise
int EthernetBonjourClass::addServiceRecord(const char* name, uint16_t port,
MDNSServiceProtocol_t proto)
{
#if defined(__MK20DX128__) || defined(__MK20DX256__)
return this->addServiceRecord(name, port, proto, NULL); //works for Teensy 3 (32-bit Arm Cortex)
#else
return this->addServiceRecord(name, port, proto, ""); //works for Teensy 2 (8-bit Atmel)
#endif
}
No matter what I do, when having a good spin (no crashes) the loop() get's executed I can see the webserver page using the ip address but the Teensy will never register it's hostname nor any Bonjour service records (using OSX Bonjour Browser application I can see a lot of Bonjour services of other devices in my LAN but never my arduino).
In addition none of the example sketches bundled with the library works correctly. My network seems to be OK, I tried different routers - no luck.
I tried for hours but couldn't narrow it down so far. I would like to ask:
- my WIZ820 works basically. But multicast doesn't seem to work. Is this a known limitation?
- is this library (which I think it's the newest I've found and is built on EthernetUDP rather than direct HW calls to w5100) compatible with the T3.6? Which library is a good one to test?
- are there any differences between a Teensy 3.0 to Teensy 3.6 in regards to this? Could it be that this library simply won't work on a 3.6 but would work fine on 3.0/3.1/3.2?
- Are there any plans to include Bonjour in the Teensy library of Ethernet?
- any pointer on how to troubleshoot this?
any help would be very much appreciated! thanks!!!!
This is my code:
Code:
// Illustrates how to register a Bonjour service.
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetBonjour.h>
#include <T3Mac.h>
EthernetServer server(80);
// for measuring how long a routine takes
uint32_t time_start, time_stop;
void setup()
{
//pinMode(4, INPUT_PULLUP);
//pinMode(10, INPUT_PULLUP);
delay(1); // allow time for both pins to reach 3.3V
// Open serial communications and wait for port to open:
Serial.begin(115200);
// Wait here for up to 10 seconds to see if we will use Serial Monitor, so output is not lost
while((!Serial) && (millis()<10000)); // wait until serial monitor is open or timeout,
Serial.print(millis());
Serial.println(" msec to start serial");
Serial.println("myBonjour");
char ID[32];
sprintf(ID, "%08lX %08lX %08lX %08lX", SIM_UIDH, SIM_UIDMH, SIM_UIDML, SIM_UIDL);
Serial.print("Teensy3 128-bit UniqueID: ");
Serial.println(ID);
pinMode(12, INPUT); // help make sure MISO is input to Teensy
delay(1000);
Serial.print("MAC from Teensy: ");
read_mac();
print_mac();
Serial.println();
uint8_t tries=1;
uint8_t flag=0;
// start the Ethernet connection, try 8 times
do
{
Serial.print("Try ");
Serial.print(tries);
Serial.print(":");
flag = ethernet_start(mac, true); // 0 if failed
Serial.print(flag);
Serial.print(" ");
}
while ((tries++ < 5) && (flag == 0));
if (0!=flag)
{
// Ethernet started OK
Serial.print("Ethernet started after ");
}
else
{
Serial.print("Ethernet start failed even after ");
}
Serial.print(tries-1); // loop already incremented it
Serial.println(" attempts");
for (byte thisByte = 0; thisByte < 4; thisByte++)
{
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
if (thisByte < 3) Serial.print("."); // don't print trailing period
}
Serial.println();
// Initialize the Bonjour/MDNS library. You can now reach or ping this
// Arduino via the host name "arduino.local", provided that your operating
// system is Bonjour-enabled (such as MacOS X).
// Always call this before any other method!
EthernetBonjour.begin("arduino"); //standart name is arduino
// Now let's register the service we're offering (a web service) via Bonjour!
// To do so, we call the addServiceRecord() method. The first argument is the
// name of our service instance and its type, separated by a dot. In this
// case, the service type is _http. There are many other service types, use
// google to look up some common ones, but you can also invent your own
// service type, like _mycoolservice - As long as your clients know what to
// look for, you're good to go.
// The second argument is the port on which the service is running. This is
// port 80 here, the standard HTTP port.
// The last argument is the protocol type of the service, either TCP or UDP.
// Of course, our service is a TCP service.
// With the service registered, it will show up in a Bonjour-enabled web
// browser. As an example, if you are using Apple's Safari, you will now see
// the service under Bookmarks -> Bonjour (Provided that you have enabled
// Bonjour in the "Bookmarks" preferences in Safari).
int res = EthernetBonjour.addServiceRecord("test._http",
80,
MDNSServiceTCP, NULL);
Serial.println("res="+String(res));
}
/**
* Try to begin ethernet with mac value, which means using DHCP.
*
* For non-DHCP different constructor with GW, etc is used.
* @param verbose output status if true
* @see https://www.arduino.cc/en/Reference/Ethernet
* @return 0 if failed, 1 if success
*/
int8_t ethernet_start(uint8_t mac[], boolean verbose)
{
int8_t status = 0; // 0 = failed
time_start = millis();
status = Ethernet.begin(mac);
time_stop = millis();
if (verbose)
{
if (0==status)
{
Serial.print("Fail DHCP after ");
}
else
{
Serial.print("OK DHCP after ");
}
Serial.print(time_stop-time_start);
Serial.println(" msec");
}
return status;
}
void loop()
{
// This actually runs the Bonjour module. YOU HAVE TO CALL THIS PERIODICALLY,
// OR NOTHING WILL WORK! Preferably, call it once per loop().
EthernetBonjour.run();
// The code below is just taken from the "WebServer" example in the Ethernet
// library. The only difference here is that this web server gets announced
// over Bonjour, but this happens in setup(). This just displays something
// in the browser when you connect.
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("Hello from a Bonjour-enabled web-server running ");
client.println("on your Arduino board!");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}