Post topics, source code that relate to the Arduino Platform

User avatar
By johnlerrington
#87981 I have a Lolin NodeMCU monitoring my network via pings and using 8 digital outputs to drive LEDs (active LOW).

A second identical NODE is configured the same but without all LEDs connected. (test system)

I developed a program on the test system to log the averaged responses to SPIFFS and access the file via FTP. It all works fine, except that sometimes the ftp server closes for a short time when I try to download the file.

I load the SAME program to an identical board - the only difference is all 8 LEDS are connected (via resistors to D0 - D7.

FTP does not work (connection timed out) and the LED on D0 - which should be continuous on - gets turned off.

Is anyone aware of any conflict between FTP and D0 (GPIO16)? Or anything else that might stop FTP from working?
User avatar
By johnlerrington
#88017 Thanks Pangolin; I've discovered two issues, and(partly) resolved one;
The NODE responds differently following a reset!
Wiring: D0 - D7 each connected via an LED and resistor to V+
here is the code I wrote to test this behaviour;
upload it and the wifi gets reported as off; press reset and it works; press again and it fails ...
Code: Select all/*****************************************************************************
  sketch to test wifi reporting issue on NodeMCU
  D0-D7 all configured as outputs and each connected via an LED & resistor to V+
  Dpin0 = GPIO16 used to indicate wifi status Dpin0 LOW LED on showing Wifi on.
****************************************************************************
*/
#include <ESP8266WiFi.h>

// to do the pin mapping for the Lolin NodeMCU pins D0 - D8
const int dPin[] = {16, 5, 4, 0, 2, 14, 12, 13, 15};

const char* ssid     = "TALKTALKCC34C4";
const char* password = "MVGGX799";

void flashLeds() { //short flash to test leds all working
  for (int i = 0; i <= 8; i++) {digitalWrite(dPin[i], 0);  }
  delay(200);
  for (int i = 0; i <= 8; i++) {digitalWrite(dPin[i], 1);  }
  delay(200);
}


void setup()
{
  // Begin serial connection at 74880 baud
  Serial.begin(74880);
  delay(1000); // serial comms is disturbed during a restart

  //set up LED pins as outputs & test them
  for (int i = 0; i <= 8; i++) { pinMode(dPin[i], OUTPUT);  }
  flashLeds();
  flashLeds();

  // Connect to WiFi access point
  bool stationConnected = WiFi.begin(ssid, password);
  delay(200); //allow time to connect
  // Check if connection errors
  if (!stationConnected)
  {
    Serial.println("Error, unable to connect specified WiFi network.");
    digitalWrite(dPin[0], 1); //indicate wifi not connected
  }
  Serial.print("Connecting to AP...");
  while (WiFi.status() != WL_CONNECTED)  // Wait until connection completed
  {
    delay(200);
    Serial.print(".");
  }
  Serial.print("Ok\n");
 
  digitalWrite(dPin[0], 0); //indicate wifi connected
}

void loop()
{
  if (WiFi.status() == WL_CONNECTED) digitalWrite(dPin[0], 0); else {
    digitalWrite(dPin[0], 1);
    Serial.print("WiFI down!!!");
    Serial.println(WiFi.status());
  }
  Serial.println("*****once more around the loop*****");
 
}//loop
User avatar
By pangolin
#88031 We have a few things to talk about here.
1) you dont need that pin mapping: the ArduinoIDE has already done it for you
so you could (should) say {D0,D1,D2....};
2) The connection code is cumbersome and mostly redundant AND will confuse you:
The likelihood of the first begin connection is next to zero - it takes time, often more thn your arbitrary 200mS so you will probably always get get "unable..." message, even though all is fine and it is still trying.
The "while (WiFi.status() != WL_CONNECTED) // Wait until connection completed" is all you need
3) The truth is the code is not behaving differently after a reset - all that is changing is the time that WiFi takes to connect. I guarantee that if you did this long enough, at some point you will get sevearl successful connects in a row and also several (erroneous) "fails" in a row.
4) While the code is typical of what you see in sample sketches...it is probably the worst possible way to do it. Examples are [i]examples[/i], not solid reliable production code! Look at "WiFi events" a good example is here. Using these, you don't need the constant check in the loop, nor do you need the WiFi.begin (at least after you have made one successful connection) See https://8266iot.blogspot.com/2019/02/st ... artup.html
and
https://arduino-esp8266.readthedocs.io/ ... mples.html