The Arduino (RPi Pico W) startup code has been significantly enhanced, allowing a range of choices for the source of WiFi and other configuration data. This includes menus for selecting startup options._

Softata Repository

Arduino Sketch Settings

Previously the Arduino sketch runs according to some fixed settings embedded in functional code or headings.

  • WiFi SSID
  • WiFi Password
  • Debug Messages On/Off
  • Serial Messages Mode
  • Service Hostname
  • Azure IoT Hub
    • HubName
    • DeviceName
    • Device Connection String

Note that the file location of these settings have been collected into one location:

NetworkSettings.h

Comment

With the inclusion of settings being stored in the simulated EEProm (actually in flash), there is now a range of options for obtaining these settings at startup:

  • Fixed in a header
  • EEProm (flash)
  • User prompt over USB Serial
  • User Prompt over Bluetooth
  • Called in code with the settings as parameters.
enum ConnectMode: byte {wifi_is_set, from_eeprom, is_defined, wifiset, serial_prompt, bt_prompt };

In the recent version of this code, a header define specified which mode was used.

A call is made from setup() such as:

bool res = FlashStorage::WiFiConnectwithOptions( connectMode, debug);
  • connectMode is as per the enum above.
    • Its default value is defined in NetworkSettings.h eg:
      #define WIFI_CONNECT_MODE from_eeprom
  • debug true/false determines if serial debug messages are displayed if and only if SOFTATA_DEBUG_MODE is defined in NetworkSettings.h. eg:
           #define SOFTATA_DEBUG_MODE

Debug Messages

There are many debug messages that can be generated at runtime. When running in “production” mode, especially if “headless”, you might not want these. There are now options to disable them.

Whether debug messages are generated depends upon options wrt USB Serial. These are specified in Serial_Macros.h. Essentially what these do is make the Serial.print etc commands active or not. Each Serial.print()/Serial.println() command is actually coded as Serial_print()/Serial_println() etc. Depending upon the coded setting and a contextual menu as a final choice, these macros manifest as:

  • Serial.print() etc
    • USB Serial
  • {delay(100)}
  • {}
  • Serial1.print() etc
  • Serial2.print() etc
  • BTSerial.print() etc

The second and third options effectively replace them with no action.

The selected option here is hardcoded by uncommenting one option in Serial_Macros.h.

USB Serial Debug messages can be generated and displayed in a serial terminal such as the Arduino IDE Serial Monitor, or Putty etc. To enable this, define SOFTATA_DEBUG_MODE which then sets the USE_USB_SERIAL in Serial_Macros.h.

When run in this mode you get a menu in the terminal asking for final confirmation that you want Serial Debug messages:

		S O F T A T A

Use Serial Debug? [Y](Default) [N]
	--- 10 secs to respond. ---
	------------------------

Serial Debug on.

When run in any of the other modes, you do not get this menu.

Connect Mode Menu

If running in USB Serial Debug Mode you get a second menu at startup:

Booting
WIFI
Please select source of Wifi Configuration.
Default: 2.
1. WiFi is Set. Call with parameters.Ignore
2. From EEProm.
3. Is defined in header.
4. Serial prompt for details.
5. Bluetooth prompt for details.
	--- 5 secs to respond. ---
	---------------


WiFi ConnectMode: is_defined

There is a hardcode option for this defined in NetworkSettings.h that is used as the default eg:

#define WIFI_CONNECT_MODE from_eeprom

EEProm Menu

If the hardcoded WIFI_CONNECT_MODE option is from_eeprom then the following occurs:

If not in Serial Debug mode then an attempt is made to read the data from EEProm without any prompts. Otherwise:

  • A check is made that the “KEY” is correctly in the first 4 bytes of that storage. See Connect2WiFi.h for the KEY.
  • If so then the following menu is displayed:
WiFi ConnectMode: from_eeprom
Key found. (1370) at start of EEProm
Do you wish to reflash the EEProm with new WiFi data? [Y/y] [N/n](Default).
	--- 5 secs to respond. ---
	---------------------
  • If N is entered or no entry prior to the timeout, then no reflash and the device continues on to read the connect settings from the EEProm and to then connect to the WiFi.
  • if Y is entered the user is prompted to enter the values for each of the settings.
    • When complete the SSID and Password are verified by attempting to connect to the WiFi
    • If correct then the values are written to the EEProm.
    • They are then read back in and WiFi is connected to.
  • If they key wasn’t found then the user is prompted to enter and store new values as above.

WiFi Connection Failure and Inbuilt LED Flash Signatures

If the WiFi connection fails, then a message is sent to the Serial Debug, if available. It then runs a busy loop with a one second period consisting of:

  • The inbuilt LED flashes 4 times followed by a very short delay.

Thus the device can be observed without a serial terminal to see if has failed to connect.

  • Flash codes are also used when the device is updated OTA (Over-The-Air).
  • When the device has completed booting/setup the inbuilt LED maintains is long flash until connected to by a Softata app. Once connected it flashes at 4x that rate.

In Softata.h See:

#define UNCONNECTED_BLINK_ON_PERIOD 4000
// Connected blink rate is 1/4 of this.
  • And when Telemetry is sent, the LED goes high for transmission. Then there are 2 very fast flashes.

 TopicSubtopic
<  Prev:   Sample RPi Pico Sketches
   
 This Category Links 
Category:Softata Index:Softata
  Next: > Softata
<  Prev:   Softata