How do you save Esp32 local IP address to apps via bluetooth?

I am trying to save esp32 local ip address to my apps via bluetooth. Need kind support in this regards. my apps show only 2 digit like 48 or 49 or 50 instead of local ip address 192.168.1.1

my device is esp32 dev module. my apps is uploaded here for reference and arduino
SyncIP (1).aia (4.5 KB)
code given below-

#include "BluetoothSerial.h" 
#include <WiFi.h>

BluetoothSerial ESP_BT;  
WiFiServer server(80);

const char* ssid = "abc";  //replace
const char* password =  "abc123"; //replace

char switchstate;

void setup() {
  Serial.begin(115200);
  ESP_BT.begin("ESP32");
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {delay(1000); Serial.println("Connecting to WiFi..");} Serial.println(WiFi.localIP());
  server.begin();
  }
 
void loop(){
  while(ESP_BT.available()>0){
  switchstate = ESP_BT.read();
  Serial.println(switchstate);
  
    //if(switchstate  == '1'){IPAddress localIP = WiFi.localIP(); String ipString = localIP.toString(); ESP_BT.print(ipString); Serial.println(ipString); delay(1000);}}}
    if(switchstate  == '1'){IPAddress localIP = WiFi.localIP(); unsigned long ipAddressValue = localIP; ESP_BT.print(ipAddressValue); Serial.println(ipAddressValue); delay(1000);}}}
    //if(switchstate  == '1'){String ipAddress = WiFi.localIP().toString(); ESP_BT.println(ipAddress); Serial.println(ipAddress);}}}

SyncIP.txt (1.1 KB)
SyncIP (1).aia (4.5 KB)

Your blocks (for the other board readers)

The IP address should be sent as text, not a single byte.

You had it in your sketch, but it got commented out?

//if(switchstate == '1'){IPAddress localIP = WiFi.localIP(); String ipString = localIP.toString(); ESP_BT.print(ipString); Serial.println(ipString); delay(1000);}

When you print to BlueTooth, use println() to supply the required end of message Line Feed delimiter.

To send and receive Text, follow this standard Delimiter advice:

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

A simple sample:

Here is a simple BlueTooth text receiver sample, for single value per line:
blocks
initialize global message to


1 Like