Ethernet-featherwing Docs URL

Can someone confirm that the website on the featherwing package actually works.

I tried https://docs.particle.io/ethernet-featherwing

Try this: https://docs.particle.io/datasheets/accessories/mesh-accessories/#ethernet-featherwing

Maybe @rickkas7 can fix.

Oops - missed that one. I’ll fix that tomorrow.

2 Likes

I have a question about using the Ethernet FeatherWing that I haven’t been able to find an answer to, yet. The docs page mentioned above suggests that if you plug a Xenon into the Ethernet FeatherWing, the firmware will recognize its presence, and network connectivity functions will just work. Correct, or do we need to also manually include a library for the board, or something?

I’ve got some code where I’m conditionally compiling functionality for either a gateway or leaf node device depending on the definitions of constants like Wiring_WiFi, Wiring_Cellular, and Wiring_Mesh. So if I’m targeting my Argon device, it will pick up that it has Mesh and WiFi, and compile the gateway functions accordingly. Likewise, if Mesh and Cellular are defined for a Boron. And if Mesh is defined, but not WiFi or Cellular, then it must be a Xenon leaf node device.

But obviously, the IDE can’t know at compile time whether there’s an Ethernet board attached, so I’m going to need some sort of override define. No problem there.

So my only question is just to know when I turn on my Ethernet override #define, do I also need to include any additional libraries, or run any additional setup functions to initialize it?

There’s a flag in configuration flash that determines whether Ethernet detection is attempted or not. If you checked the Ethernet checkbox during mobile app setup, it will set the device configuration flag.

You can also set it through code using this:

STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION));

You only need to set it once (the setting is saved), though there is no harm in setting it every time.

The reason is that the Ethernet FeatherWing nRESET and nINTERRUPT pins are regular GPIO pins, and if the device probed for Ethernet all the time, it could conceivably cause problems for products that use those pins for actual GPIO.

To determine if a platform MIGHT have Ethernet at compile time, use a

#if Wiring_Ethernet

This will be true for any mesh platform, and false for earlier generations. This doesn’t mean there is an Ethernet adapter, but it means the Ethernet class is available.

Since you probably most care if the Ethernet interface is up - connected to an Ethernet switch, you could then check Ethernet.ready() to determine if there’s actually an Ethernet Featherwing and it’s connected to Ethernet.

5 Likes

This would make a nice addition to the the wing’s documentation. Thanks for the info!

1 Like

Aaaah, so it does know at compile-time, because you know the device config? I assume that’s true for both the Cloud and Desktop IDEs?

So, I should be able to just use Wiring_Ethernet in the same manner that I’ve been using Wiring_Mesh and friends? Excellent. I’ve already added a define that lets you override and force it to compile the code as a leaf node even if the device would normally be considered a gateway, so that should cover the bases.

If I understood Rick correctly #if Wiring_Ethernet will be true for any mesh device irrespective of the actual presence of an Ethernet FeatherWing and/or the setting whether to use the Ethernet FeatherWing as uplink or not.

So, I'd say: "No, at compile time you can't distinguish whether the device is setup to use Ethernet connection."

The compiler only knows what platform and what device OS version is targeted but has no knowledge about an individual device. You can flash one binary to multiple devices (sharing the same platform and version) being setup with the detection flag set or cleared. The distinction needs to be made at runtime.

Oh, I missed that in my first reading. I thought the first paragraph said what I wanted to hear, and misinterpreted what he said later.

I guess I’ll go back to my own #define for that.

This example program shows the various combinations that are possible and how to detect them:

#include "Particle.h"

SerialLogHandler logHandler;

SYSTEM_THREAD(ENABLED);

const unsigned long CHECK_INTERVAL = 5000;
unsigned long lastCheck = 0;

void setup() {
	Serial.begin();
}

void loop() {
	if (millis() - lastCheck >= CHECK_INTERVAL) {
		lastCheck = millis();

#if Wiring_Ethernet
		Log.info("this device could have Ethernet (is 3rd generation)");

		if (System.featureEnabled(FEATURE_ETHERNET_DETECTION)) {
			Log.info("FEATURE_ETHERNET_DETECTION enabled");

			if (Ethernet.ready()) {
				Log.info("Ethernet ready (has link and IP address %s)", Ethernet.localIP().toString().c_str());
			}
			else {
				uint8_t mac[6];
				if (Ethernet.macAddress(mac) != 0) {
					Log.info("Ethernet present but not ready");
				}
				else {
					// the macAddress function returns 0 if there is no Ethernet adapter present
					Log.info("Ethernet detection enabled, but no Ethernet present");
				}
			}
		}
		else {
			Log.info("FEATURE_ETHERNET_DETECTION not enabled, so Ethernet will not be used (even if present)");
		}
#else
		Log.info("no Ethernet (1st or 2nd generation device)");
#endif
	}
}

4 Likes

@rickkas7

Took your code and set it for the console.

#include "Particle.h"

SerialLogHandler logHandler;

SYSTEM_THREAD(ENABLED);

const unsigned long CHECK_INTERVAL = 30000;
unsigned long lastCheck = 0;

void setup() {
     pinMode(D7, OUTPUT);
     
     STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION));
    // Ethernet.setListenTimeout(10);
    // Ethernet.connect();
}

void loop() {
	if (millis() - lastCheck >= CHECK_INTERVAL) {
	    digitalWrite(D7, HIGH);    
		lastCheck = millis();

#if Wiring_Ethernet
        Particle.publish("this device could have Ethernet"," (is 3rd generation)", 60, PRIVATE); 

		if (System.featureEnabled(FEATURE_ETHERNET_DETECTION)) {
			  Particle.publish("FEATURE_ETHERNET_DETECTION"," enabled", 60, PRIVATE); 

			if (Ethernet.ready()) {
				  Particle.publish("Ethernet ready (has link and IP address ",Ethernet.localIP().toString().c_str(), 60, PRIVATE); 
			}
			else {
				uint8_t mac[6];
				if (Ethernet.macAddress(mac) != 0) {
					  Particle.publish("Ethernet present but"," not ready", 60, PRIVATE); 
				}
				else {
					// the macAddress function returns 0 if there is no Ethernet adapter present
					  Particle.publish("Ethernet detection enabled, ","but no Ethernet present", 60, PRIVATE); 
				}
			}
		}
		else {
			  Particle.publish("FEATURE_ETHERNET_DETECTION not enabled, ","so Ethernet will not be used (even if present)", 60, PRIVATE); 
			  
			  
			  
			  
			  
		}
#else
		Log.info("no Ethernet (1st or 2nd generation device)");
					  Particle.publish("no Ethernet ","(1st or 2nd generation device)", 60, PRIVATE); 
#endif
	}
	
	digitalWrite(D7, LOW);    
}



 
  
  
  

but does the code above allow the Particle Featherwing to be plug and play?

Meaning, without the featherwing my Xenon works if connected to a mesh, with the featherwing my Xenon has internet and is still connected to the mesh.

For long winded explanation see blog at High School Robotics Course using the Particle.io Mesh Devices Blog - #52 by rocksetta

solved it from your other posts. see code above.