Blinking the last IP byte upon setup...

Hi,
I would like to get some info about the assigned IP after booting into a WiFi network on the built in LED.
(being an ESP or an Arduino should not matter) blinking the last byte would suffice.

Something like -..-....-... for 243 or - -..-...... for 016. or .................... for "could not connect".

Does that exist, or should I do it fom scratch?

Does that exist, or should I do it fom scratch?

Roll your own

What data type is the IP held in ?

UKHeliBob:
Roll your own

What data type is the IP held in ?

Currently it is a

static IPAddress ip;

But extracting the last byte is not the problem.
I just wanted to avoid reinventing the wheel if someone had done it.
Ii nobody did it, i'll post the code on Github. I believe, it could be useful.

I think it unlikely that anyone has done it but even if they had it would probably take longer to find it and adapt it to your needs than it would take to write it from scratch.

If you were going to use Morse, you could certainly find existing code. Given your own simpler coding system though, it's probably best to just write it from scratch.

I am a bit confused.
Here is my testing code:

#include <ESP8266WiFi.h>
#define SERIAL_SPEED 9600

static IPAddress ip;
#define STDLED     D4   // GPIO02 (& Console2 TX)


void blinkByte(byte value, byte pin)
{
  byte part;
  byte i;
  Serial.println("Mark ");   
  pinMode(STDLED, OUTPUT);
  digitalWrite(STDLED, false);
  delay(2000);
  digitalWrite(STDLED, true);
  Serial.print("Blinking value: ");  Serial.println(value);
  part = value / 100 % 10;
  Serial.print(part); Serial.print(" : ");
  for (i = 0; i <= part; i++) {
    digitalWrite(STDLED, false);
    delay(100);
    digitalWrite(STDLED, true);
    delay(500);
  }
  delay (1000);
  part = value / 10 % 10;
  Serial.print(part); Serial.print(" : ");
  for (i = 0; i <= part; i++) {
    digitalWrite(STDLED, false);
    delay(100);
    digitalWrite(STDLED, true);
    delay(500);    
  }
  delay(1000);
  part = value % 10;
  Serial.println(part);
  for (i = 0; i <= part; i++) {
    digitalWrite(STDLED, false);
    delay(100);
    digitalWrite(STDLED, true);
    delay(500);
  }
}

void setup() {
  // put your setup code here, to run once:
  // Serial initialisation
  Serial.begin (SERIAL_SPEED); // On USB port
  Serial1.begin(SERIAL_SPEED); // On GPIO2 / D4
  Serial.println();  

  blinkByte( 222, STDLED);


}

void loop() {
  // put your main code here, to run repeatedly:

}

The byte is decoded correctly into the separate digits.
But the LED blinks not 2:2:2 but 2:3:3.
? ? ?
'I am using 3 times the same for loop with the same input and get different results?
Why?

It prints correctly
20:52:55.392 → Mark
20:52:57.387 → Blinking value: 222
20:52:57.387 → 2 : 2 : 2

Moving to programming questions...

So, I have done it.

It blinks the last byte (optionally the two last bytes) of the IP address upon connecting.

#define HOST_NAME "BLINK_IP"
#define WIFI_SSID          "Your SSID"
#define WIFI_PASS          "Snowden knows it"
#define SERIAL_SPEED 9600
#define STDLED     D4   // GPIO02 (& Console2 TX)
#include <ESP8266WiFi.h>
static IPAddress ip;
int wifiConnectCounter;
#define wifiMaxTries         30
#define wifiRepeatInterval   100

void blinkByte(byte value, byte pin)
{
  byte part;
  byte i;
  //Serial.println("Mark ");
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
  delay(2000);
  digitalWrite(pin, HIGH);
  delay (1000);
  //Serial.print("Blinking value: ");  Serial.println(value);

  part = value / 100 % 10;
  //Serial.print(part); Serial.print(" : ");
  for (i = 0; i < part; i++) {
    digitalWrite(pin, LOW);
    delay(100);
    digitalWrite(pin, HIGH);
    delay(500);
  }
  delay (1000);

  part = value / 10 % 10;
  //Serial.print(part); Serial.print(" : ");
  for (i = 0; i < part; i++) {
    digitalWrite(pin, LOW);
    delay(100);
    digitalWrite(pin, HIGH);
    delay(500);
  }
  delay(1000);

  part = value % 10;
  //Serial.println(part);
  for (i = 0; i < part; i++) {
    digitalWrite(pin, LOW);
    delay(100);
    digitalWrite(pin, HIGH);
    delay(500);
  }
  delay(2000);
}

void getWiFi()
{
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  wifi_station_set_auto_connect(true);
  wifi_station_set_hostname(HOST_NAME);
  wifiConnectCounter = 1;
  Serial.println();
  while (WiFi.status() != WL_CONNECTED) {
    delay(wifiRepeatInterval);
    Serial.print(".");
    wifiConnectCounter++;
    if (wifiConnectCounter > wifiMaxTries) {
      delay(wifiRepeatInterval * 1000 * 1000);
      wifiConnectCounter = 0;
    }
  }
  ip = WiFi.localIP();
}


void setup() {
  // put your setup code here, to run once:
  // Serial initialisation
  Serial.begin (SERIAL_SPEED); // On USB port
  Serial.println();

  getWiFi();
  //blinkByte(ip[2], STDLED);
  blinkByte(ip[3], STDLED);

}

void loop() {
  // put your main code here, to run repeatedly:
}

#define is so eighties. Const is preferred unless you need a macro :wink:

wildbill:
#define is so eighties. Const is preferred unless you need a macro :wink:

I'm still listening music from my HiFi equipment that dates fom the eighties as well.
And I am happy with that.
One must not follow every fashion gimmick.

I'm still listening music from my HiFi equipment that dates fom the eighties as well.
And I am happy with that.
One must not follow every fashion gimmick.

++Karma; // :slight_smile: