Black Lives Matter - Action and Equality.
0

Hardware works but always network disconnected error
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Hardware works but always network disconnected error

by Systembolaget on Sun Apr 05, 2020 7:07 am

Hi,

I'm using two Adafruit Feather M0 RFM69 Packet Radio modules to transmit and receive remote sensor data. Now I have connected an Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor module to the receiving one in order to relay the received data onward to Adafruit IO.

I have successfully tried your WiFiNINA JSONdemo and WiFiNINA WiFiWebServer examples while temporarily disabling the receiver's radio with

Code: Select all | TOGGLE FULL SIZE
digitalWrite(8, HIGH);

WiFi.somecommand();

digitalWrite(8, LOW);

In other words, my setup seems to work well, as far as either packet radio or WiFi is concerned.

However, when I try the Adafruit IO Arduino adafruitio_00_publish example, having made the required config.h changes

Code: Select all | TOGGLE FULL SIZE
#define IO_USERNAME "S#"
#define IO_KEY "aio_#"
#define WIFI_SSID "L#"
#define WIFI_PASS "6#"

#define USE_AIRLIFT

#define SPIWIFI SPI
#define SPIWIFI_SS 13
#define ESP32_RESETN 12
#define SPIWIFI_ACK 11
#define ESP32_GPIO0 -1

AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);

I only ever see "Network disconnected" as per https://learn.adafruit.com/welcome-to-adafruit-io/troubleshooting-your-adafruit-io-project. Using new Feathers and AirLifts (I ordered several) yields the same result - packet radio and WiFi examples as well as my own code work, but the Adafruit IO Arduino adafruitio_00_publish example always fails.

How should I troubleshoot this issue further?

Much appreciated & I hope you're all safe!

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Mon Apr 06, 2020 5:15 pm

All your WiFi related example sketches work, tried the WiFiNINA WiFiSSLClient, that works, too, see below - but there is no way I can get any of the Adafruit IO connection sketches to work, even though I disable the radio at the start of setup() with digitalWrite(8, HIGH); as for the WiFi examples. That will become an issue later, I guess, when wanting to bridge from radio to WiFi to Adafruit IO, but for now I would be happy if I can connect reliably to Adafruit IO at all. Tried with all brand new Feathers and FeatherWings. Generated new user key. No joy. Only WiFi examples work. Found no other user in forums using the Feather with FeatherWing combo I bought who has working code.

Any ideas what else I can try?

Code: Select all | TOGGLE FULL SIZE
23:07:00.851 -> Attempting to connect to SSID: L#
23:07:16.171 -> Connected to wifi
23:07:16.171 -> SSID: L#
23:07:16.171 -> IP Address: 1#
23:07:16.171 -> signal strength (RSSI):-59 dBm
23:07:16.171 ->
23:07:16.171 -> Starting connection to server...
23:07:18.817 -> connected to server
23:07:18.925 -> HTTP/1.1 200 OK
23:07:18.925 -> Accept-Ranges: bytes
23:07:18.925 -> Access-Control-Allow-Origin: https://ton.smf1.twitter.com
23:07:18.925 -> Access-Control-Allow-Origin: https://ton.smf1.twitter.com
23:07:18.925 -> Age: 100
23:07:18.925 -> cache-control: must-revalidate, max-age=600
23:07:18.925 -> content-disposition: attachment; filename=json.json
23:07:18.925 -> Content-Type: application/json;charset=utf-8
23:07:18.925 -> Date: Mon, 06 Apr 2020 21:07:18 GMT
23:07:18.925 -> expires: Mon, 06 Apr 2020 21:17:18 GMT
23:07:18.925 -> Last-Modified: Mon, 06 Apr 2020 21:05:38 GMT
23:07:18.925 -> Server: ECS (fcn/41AF)
23:07:18.925 -> strict-transport-security: max-age=631138519
23:07:18.925 -> timing-allow-origin: *
23:07:18.925 -> X-Cache: HIT
23:07:18.925 -> x-connection-hash: e1d7dc7b2daf77fbd99e9b8f38cb97ba
23:07:18.925 -> x-content-type-options: nosniff
23:07:18.925 -> x-frame-options: SAMEORIGIN
23:07:18.925 -> x-response-time: 121
23:07:18.925 -> x-transaction: 0053865b000ebc45
23:07:18.925 -> x-xss-protection: 0
23:07:18.925 -> Content-Length: 197
23:07:18.925 -> Connection: close
23:07:18.925 ->
23:07:18.925 -> [{"following":false,"id":"20731304","screen_name":"adafruit","name":"adafruit industries","protected":false,"followers_count":173100,"formatted_followers_count":"173K followers","age_gated":false}]
23:07:18.995 -> disconnecting from server.
23:07:18.995 -> Read 972 bytes

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by brubell on Tue Apr 07, 2020 2:23 pm

Could you try running this Adafruit MQTT Library example designed for the AirLift + Adafruit IO:

https://github.com/adafruit/Adafruit_MQ ... irlift.ino

and paste the output from the serial monitor?

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Tue Apr 07, 2020 3:26 pm

Thanks for chiming in! I added

Code: Select all | TOGGLE FULL SIZE
  digitalWrite(8, HIGH); // Disable RFM69 radio for WiFi communication
right at the start of setup() to disable the RFM69 radio to enable WiFi to work, and I get the following serial output

Code: Select all | TOGGLE FULL SIZE
21:17:38.344 -> Attempting to connect to SSID: L#
21:17:48.502 -> Connected to wifi
21:17:48.502 -> SSID: L#
21:17:48.502 -> IP Address: 1#
21:17:48.538 -> signal strength (RSSI):-63 dBm
21:17:48.538 -> Connecting to MQTT... MQTT Connected!
21:17:52.000 ->
21:17:52.000 -> Sending val 0 to test feed...OK!
21:17:54.015 ->
21:17:54.015 -> Sending val 1 to test feed...OK!
21:17:56.012 ->
21:17:56.012 -> Sending val 2 to test feed...OK!
21:17:58.018 ->
21:17:58.018 -> Sending val 3 to test feed...OK!
So, if this works, why not the Adafruit IO examples? What could the difference be between your test code and the adafruitio_00_publish example?

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Tue Apr 07, 2020 6:30 pm

I noticed that your MQTT example has these includes

Code: Select all | TOGGLE FULL SIZE
#include <WiFiNINA.h>
#include <SPI.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

but the adafruitio_00_publish example from the https://learn.adafruit.com/adafruit-io- ... t/usage-3# page only includes

Code: Select all | TOGGLE FULL SIZE
#include "AdafruitIO_WiFi.h"

and not even includes #include <SPI.h> (unless AdafruitIO_WiFi.h includes it) so, is there possibly something missing?

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Thu Apr 09, 2020 9:44 am

So, how should I best proceed now, meaning to get Adafruit IO to work as described on the AirLift page?

Your MQTT example worked right away, the AirLift adafruitio_00_publish example and others in the Adafruit IO example sketch list don't : (

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by brubell on Fri Apr 10, 2020 9:59 am

and not even includes #include <SPI.h> (unless AdafruitIO_WiFi.h includes it) so, is there possibly something missing?


The Adafruit IO Library contains these #includes if the AirLift is defined in Config.h (https://github.com/adafruit/Adafruit_IO ... LIFT.h#L22)

I'm using two Adafruit Feather M0 RFM69 Packet Radio modules to transmit and receive remote sensor data. Now I have connected an Adafruit AirLift FeatherWing – ESP32 WiFi Co-Processor module to the receiving one in order to relay the received data onward to Adafruit IO.

Could you link the product ID's you're using?

I'm going to try to replicate this next week on my setup to ensure it's not a networking issue.

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Sat Apr 11, 2020 11:10 am

Thanks for following this thread under the difficult circumstances first of all!

My set-up is as follows:

https://www.adafruit.com/product/3176 (TX)
https://www.adafruit.com/product/3176 (RX)
https://www.adafruit.com/product/4264 (relay RX collected data to Adafruit IO, etc.)

Your MQTT example works. The AirLift examples don't. Any help would be much appreciated, because I want to monitor an array of remote trees, and the non-addressed/addressed RFM69 to RFM69 transport is very reliable. But, how to then forward it online with that Adafruit-featured ESP32 AirLift breakout board? I am totally stuck : (

Thanks!

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Thu Apr 16, 2020 6:36 am

Just for reference while awaiting feedback regading AirLift WiFi/Adafruit IO issues.

Arduino IDE - version 1.8.10
SPI.h - comes with Arduino IDE
WiFiNINA (Adafruit flavour) - downloaded from https://github.com/adafruit/WiFiNINA
Adafruit_IO_Arduino - downloaded from https://github.com/adafruit/Adafruit_IO_Arduino
Adafruit_MQTT_Library - downloaded from https://github.com/adafruit/Adafruit_MQTT_Library

Not working adafruitio_00_publish.ino includes config.h which includes AdafruitIO_WiFi.h which includes AdafruitIO_AIRLIFT.h which includes AdafruitIO.h, Adafruit_MQTT.h, Adafruit_MQTT_Client.h, Arduino.h, SPI.h and WiFiNINA.h

Working adafruitio_secure_airlift includes WiFiNINA.h, SPI.h, Adafruit_MQTT.h which includes Arduino.h and Adafruit_MQTT_Client.h which includes Client.h and Adafruit_MQTT.h

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Thu Apr 16, 2020 5:19 pm

Another day, new boards, same result - none of the Adafruit IO Arduino examples work and hang forever at io.connect(), but the MQTT adafruitio_secure_airlift example does work.

It seemed straightforward here https://learn.adafruit.com/adafruit-io- ... ft/usage-3 because then other users and I could tackle the main task: How to RX radio packets with the RFM69HCW and then TX them onwards to Adafruit IO.

During WiFi usage, the radio module has to be temporarily disabled, that much I know; but to actually write working TX-RX radio-WiFi ping-pong code without adafruitio_00_publish working, one is entirely snookered.

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by brubell on Sat Apr 18, 2020 10:37 am

Ok, I had some time to look at this issue today on hardware. It seems like the RFM69HCW's CS is conflicting with a pin on the AirLift's ESP32.

In Adafruit IO Arduino, if you want to disable to the CS pin prior to initialization of the wifi radio, you can add a line to disable the pin here: https://github.com/adafruit/Adafruit_IO ... IFT.h#L155

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Sat Apr 18, 2020 11:20 am

Thanks a lot for coming back to this conundrum, very much appreciated.

As you can glean from my first post, I already disable the Feather M0's CS pin (pin 8 pulled HIGH) to enable WiFi communication to work. Nonetheless, only the adafruitio_secure_airlift and similar examples do work, but adafruitio_00_publish.ino and similar examples do not.

Since the more cumbersome method to publish only using the MQTT library does work, I now need to find out how to disable/enable the radio programmatically, so I can 1. RX the other packet radio nodes' data with the Feather M0 RCW69HCW and then 2. TX them onwards to Adafruit IO with the connected AirLift FeatherWing ESP32.

Still, it would be good to get it to work with the Adafruit IO library as described in the guide.. After all, I bought that combination of Adafruit PCBs after our February discussion ; )
Last edited by Systembolaget on Sat Apr 18, 2020 11:41 am, edited 1 time in total.

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by brubell on Sat Apr 18, 2020 11:25 am

Could you try disabling the rfm69 cs pin in the Adafruit IO Arduino library line linked above?

brubell
 
Posts: 891
Joined: Fri Jul 17, 2015 10:33 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Sat Apr 18, 2020 12:22 pm

I added digitalWrite(8, HIGH); in line 164 of the library, instead of disabling it at the start of setup() in the main code, but still only get Connecting to Adafruit IO...................................... on the serial monitor with adafruitio_00_publish.

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Hardware works but always network disconnected error

by Systembolaget on Tue Apr 21, 2020 12:17 pm

Still no joy at all... with a Feather M0, Feather M4 or Feather Whatever... all brand new... none of the Adafruit IO library examples work, only the more cumbersome MQTT route gives my set-ups a bit of an airlift.

Any other ideas why that is?

Here's the RX node's test via good old MQTT; three TXed inputs simulated with a random number generator for the time being. The next hurdle will be that the Feather M0 RFM69 packet radio must be disabled while the FeatherWing ESP32 transmits via WiFi radio, so that means some kind of ping-pong code will be necessary.

Code: Select all | TOGGLE FULL SIZE
#include <WiFiNINA.h> // Adafruit's WiFiNINA flavour, use version 1.4.0
#include <SPI.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#define SPIWIFI       SPI // SPI port
#define SPIWIFI_SS    13  // Chip select pin
#define ESP32_RESET   12  // Reset pin
#define SPIWIFI_ACK   11  // Ready pin
#define ESP32_GPIO0   -1  // Not connected

#define WLAN_SSID "L#"
#define WLAN_PASS "6#"

#define AIO_SERVER "io.adafruit.com" // MQTT broker/server host
#define AIO_SERVERPORT 8883 // Secure port, 1883 insecure port
#define AIO_USERNAME "S#"
#define AIO_KEY "aio_F#"

struct transmission // Later, the values will arrive from various other RFM69HCW nodes
{
  bool feed1; // Momentary switch, values 0 or 1
  byte feed2; // Potentiometer, values 10 - 170 (for this particular servo)
  int feed3; // Photoresistor, values 0 - 1023 (1023 at maximum brightness)
} nodeTX;

const int intervalFeed1 = 6000, intervalFeed2 = 12000, intervalFeed3 = 20000; // Time until next .publish event
unsigned long nowFeed1 = 0, nowFeed2 = 0, nowFeed3 = 0; // Timestamp

// An idle status is assigned when WiFi.begin() is called; it remains
// active until the connection attempt fails (WL_CONNECT_FAILED) or a
// connection is established (WL_CONNECTED)
int status = WL_IDLE_STATUS;

// Instances an object from the WiFiNINA library to connect and
// transfer data with SSL/TLS support
WiFiSSLClient client;

// Instances an object from the MQTT_Client library with the
// WiFi client, MQTT server, port and login credentials
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// Instance publishing objects from the library that correspond to
// the struct members (feed = Adafruit IO specific MQTT topic)
Adafruit_MQTT_Publish feed1 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/feed1"); // Momentary switch
Adafruit_MQTT_Publish feed2 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/feed2"); // Potentiometer
Adafruit_MQTT_Publish feed3 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/feed3"); // Photoresistor

void setup()
{
  digitalWrite(8, HIGH); // Disable RFM69 radio during WiFi communication : (

  // Only needed for debugging with computer USB connection
  Serial.begin(115200);
  while (!Serial);

  // Override the default pins with those of the AirLift breakout board
  WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESET, ESP32_GPIO0, &SPIWIFI);

  // WL_NO_MODULE is assigned when the communication with the WiFi module fails
  while (WiFi.status() == WL_NO_MODULE)
  {
    Serial.println("Communication with WiFi module failed!");
    delay(1000);
  }

  // Try to connect to the WPA/WPA2 network defined above. Once status
  // is assigned WL_CONNECTED, the connection is established
  do
  {
    status = WiFi.begin(WLAN_SSID, WLAN_PASS);
    delay(100);
  }
  while (status != WL_CONNECTED);
  Serial.println("Connected to WiFi");

  WiFi.setLEDs(255, 0, 0); // Indicate successful WiFi connection; oddball GRB colour order

  randomSeed(analogRead(0)); // For the feeds' test values
}

void loop()
{
  nodeTX.feed1 = random(2); // Later, values are TX'ed from remote RFM69HCW nodes
  nodeTX.feed2 = random(10,171);
  nodeTX.feed3 = random(-1023,1024);
  publishFeed1(); publishFeed2(); publishFeed3();
}

void publishFeed1() // One can pass the publish object and struct member to avoid function triplication, but how to pass the cast?
{
  if (millis() - nowFeed1 >= intervalFeed1)
  {
    nowFeed1 = millis(); // Record the current time

    // A call to this function establishes and also re-establishes the
    // connection to the MQTT broker/server in case of disconnection
    MQTT_connect();

    // Cast struct member to be published into one of the three
    // accepted data types (long, float, uint_32t) and publish to
    // the matching feed. When a value was successfully published,
    // .publish returns 0. Maximum publishing rate on the free tier
    // is 30 times per minute; otherwise a temporary ban ensues
    feed1.publish((long)nodeTX.feed1);
  }
}

void publishFeed2()
{
  if (millis() - nowFeed2 >= intervalFeed2)
  {
    nowFeed2 = millis();
    MQTT_connect();
    feed2.publish((long)nodeTX.feed2);
  }
}

void publishFeed3()
{
  if (millis() - nowFeed3 >= intervalFeed3)
  {
    nowFeed3 = millis();
    MQTT_connect();
    feed3.publish((long)nodeTX.feed3);
  }
}

void MQTT_connect()
{
  // Return to loop() if already connected
  if (mqtt.connected())
  {
    return;
  }

  Serial.println("Connected to MQTT");

  int8_t ret;
  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0)
  { // mqtt.connect will return 0 if connected
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000); // wait 5 seconds
    retries--;
    if (retries == 0)
    {
      // basically die and wait for WDT to reset me
      while (1)
        ;
    }
  }

  Serial.println("MQTT Connected!");
}

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Please be positive and constructive with your questions and comments.