0% found this document useful (0 votes)
12 views

Guide

This device gathers BLE data from BLE enabled devices, sends the gathered data to a server connected to the internet using Google Firebase. It requires setting up hardware including a BLE MCU, WiFi MCU, LTE modem and smartphone. The software and firmware setup includes configuring the LTE modem, downloading Arduino IDE, installing ESP32 and Firebase libraries, and uploading codes to the MCUs to establish WiFi and BLE communication and send data to Firebase.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Guide

This device gathers BLE data from BLE enabled devices, sends the gathered data to a server connected to the internet using Google Firebase. It requires setting up hardware including a BLE MCU, WiFi MCU, LTE modem and smartphone. The software and firmware setup includes configuring the LTE modem, downloading Arduino IDE, installing ESP32 and Firebase libraries, and uploading codes to the MCUs to establish WiFi and BLE communication and send data to Firebase.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Wi-Fi/LTE Modem

1. What does this device do?


- Gather BLE data from BLE enabled devices
- Send gathered data to a server connected to the internet (Google Firebase)

2. What do we do to use this device?


1) Get hardware ready
- Sensor: smart battery
Figure

- Wi-Fi module:2 pieces of ESP32


Figure
- LTE Modem: 4G LTE USB modem, 구글에서 LTE Modem 검색
Figure

- Smartphone

2) Make SW, HW setup

- LTE modem setup: SIM card 가입,


- BLE firmware
- Wi-Fi firmware
- Google firebase
- Smartphone app
LTE modem setup: SIM card 가입
Insert the SIM card provided by your cellular network provider into the modem

connect the modem to your device using a USB cable. Finally, install any necessary drivers or software provided
by the manufacturer.
Your device will automatically detect the modem and display the installation window.
Carry out installation according to system prompts.

Searching network to find SSID: 4G_UFI_****, Click connect,


input password: 12345678, and confirm.

Connect the BLE MCU(ESP32 module 1) to the WiFi MCU(ESP32 module 2)


Familiarize yourself with the pinout of the ESP32 module. It usually consists of 30 pins and we are
going to use 4 pins: 3v3 (3.3v power supply), GND (ground), TX2 (Transmit), and RX2 (Receive).
Connect the components: Use the jumper wires to connect the BLE MCU module to the WiFi MCU.
Connect the 3v3 pin of the BLE MCU to 3v3 pin on the WiFi MCU, the GND pin to the GND pin, the
TX2 pin to the RX2, and the RX2 to the Tx2.
BLE, WiFi MCU firmware
Download the Arduino Software (IDE)

https://www.arduino.cc/en/software
Download the Arduino IDE that is compatible with your computer system.
When the download finishes, proceed with the installation and please allow the driver installation
process when you get a warning from the operating system.
Choose the components to install.

Choose the installation directory.


Installation in progress.
The process will extract and install all the required files to execute properly the Arduino Software
(IDE)
Open the Arduino IDE.

File->Preferences->Additional boards manager URLs


https://dl.espressif.com/dl/package_esp32_index.json
Install the ESP32 by Espressif Systems
Tools->Board->board manager

Select the Board(DOIT ESP32 DEVKIT V1)


Tools->Board->esp32-> DOIT ESP32 DEVKIT V1

Install the Libraries for ESP32


Open a Library tool then write the name of libraries( Firebase Arduino Client Library, Firebase ESP32
Client). Then Install the libraries.
we need to select the board that we are going to use. We can do this by navigating to Tools > Port >
{Board}. The board(s) that are connected to your computer should appear here, and we need to select
it by clicking it. In this case, our board is displayed as COM9.
If you have connected your board to your computer but there is no com port
Download esp32 board usb driver and install your usb driver
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads
Copy and paste the below code here
First, We need to set WiFi name and password in the WiFi MCU code.
#define WIFI_SSID "4G_UFI_3983" // input your home or public WiFi name
#define WIFI_PASSWORD "12345678" //input your WiFi password

Click on the verify tool (checkmark). Since we are verifying the sketch, we can be sure it is going to
compile. After a few seconds, we can see the result of the action in the console (black box in the
bottom).
With the board selected, we are good to go! Click on the upload button, and it will start uploading
the sketch to the board.
When it is finished, a notification pops up in the bottom right of your IDE window. Of course,
sometimes there are some complications when uploading, and these errors will be listed here as well.

Congratulations, you have now uploaded a sketch to your Arduino board!


Run the following codes on 2 boards according to the above instructions

- I created Google Firebase for this lesson


- You can download the smartphone app from this link
https://www.mediafire.com/file/w9kqu5sal6j8r7i/app.apk/file
-Test
When you search for a battery in this application, it will display the number of available batteries.
Then, when you click on the desired battery number, it will show the information of the selected
battery.

Source code.
//Code of WiFi MCU

#include <Arduino.h>
#include <iostream>
#if defined(ESP32)
#include <WiFi.h>
#include <FirebaseESP32.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#elif defined(PICO_RP2040)
#include <WiFi.h>
#include <FirebaseESP8266.h>
#endif // firebase library

// #define FIREBASE_HOST "smart-battery-17b25-default-rtdb.asia-southeast1.firebasedatabase.app"


// the project name address from firebase id
// #define FIREBASE_AUTH "wHIT29VSAGVB5Wh8GSWXM8C8ych7horLGlT5TsaN" // the
secret key generated from firebase

#define API_KEY "AIzaSyBktHAM1PkWUCM24Wik-EX7KaWj69_6Vas"

/* 3. Define the user Email to reset the password */


#define USER_EMAIL "USER_EMAIL"

/* 4. If work with RTDB, define the RTDB URL */


#define DATABASE_URL "smart-battery-17b25-default-rtdb.asia-southeast1.firebasedatabase.app"
//<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app

#define WIFI_SSID "4G_UFI_3983" // input your home or public wifi name

#define WIFI_PASSWORD "12345678"

String converter(uint8_t str);

// Define Firebase Data object


FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

bool dataComplete, dataComplete1, dataCompleteSend;


int deviceCounter, SelectedBattery, SelectedBatteryID;
uint8_t serialData[50], deviceManufaData[50];
String checkDataID, SerialNo = "", flag;

void setup()
{
Serial.begin(9600);
Serial2.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // try to connect with wifi


Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}

Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); // print local IP address
// Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

/* Assign the API key (required) */


config.api_key = API_KEY;

/* Assign the RTDB URL */


config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);

Serial.printf("Send Email reset password link... %s\n", Firebase.sendResetPassword(&config,


USER_EMAIL) ? "ok" : config.signer.resetPswError.message.c_str());
}
void loop()
{
if (dataComplete)
{
Serial.print(" data = ");
for (int i = 0; i < 24; i++)
{
Serial.print(serialData[i], HEX);
Serial.print(" ");
}
Serial.println();
dataComplete = false;
dataCompleteSend = true;
}
if (dataComplete1)
{
String devNames = "";
for (int i = 0; i < deviceCounter; i++)
{
Serial.println(deviceManufaData[i]);
devNames += deviceManufaData[i] + '.';
}
Firebase.RTDB.setString(&fbdo, "Devices", devNames);
deviceCounter = 0;
dataComplete1 = false;
}
SelectedBattery = Firebase.RTDB.getInt(&fbdo, "SelectedBattery");
if (SelectedBattery != 0 && SelectedBattery != 255)
{
SelectedBatteryID = deviceManufaData[SelectedBattery - 1];
Serial2.write("\nSel\n");
Serial2.write(SelectedBattery);
Firebase.RTDB.setInt(&fbdo, "SelectedBattery", -1);
}
if (SelectedBattery == 0)
{
Serial2.write("\nReset\n");
Serial2.write(1);
Firebase.RTDB.setInt(&fbdo, "Connect", 0);
Firebase.RTDB.setInt(&fbdo, "SelectedBattery", -1);
Firebase.RTDB.setString(&fbdo, "Devices", " ");
checkDataID = "";
}
if (Firebase.RTDB.getInt(&fbdo, "Reset"))
{
Serial2.write("\nReset\n");
Serial2.write(1);
Firebase.RTDB.setInt(&fbdo, "Connect", 0);
Firebase.RTDB.setInt(&fbdo, "Reset", 0);
Firebase.RTDB.setString(&fbdo, "Devices", " ");
}
int8_t BatteryCheck = Firebase.RTDB.getInt(&fbdo, SerialNo + "/BatteryCheck");
Serial.print("BatteryCheck = ");
Serial.println(BatteryCheck);
if (BatteryCheck == 1)
{
Serial2.write("\nHealth\n");
Serial2.write('d');
String stringData = SerialNo;
stringData += "/BatteryCheck";
Firebase.RTDB.setInt(&fbdo, stringData, 0);
}
if (dataCompleteSend)
{
dataCompleteSend = false;
Serial.print("Firebase Status = ");
// Serial.println(Firebase.ready);

uint8_t SerialNoConvert[2];
SerialNoConvert[0] = serialData[22];
SerialNoConvert[1] = serialData[23];
SerialNo = "90"; // + dataprintHEX(SerialNoConvert, 2);
for (int i = 0; i < 2; i++)
{
SerialNo += converter(SerialNoConvert[i]);
}
Serial.print("SerialNo = ");
Serial.println(SerialNo);
if (SelectedBatteryID == SerialNo && serialData[20] < 5)
{
String serialDataHex;
for (int i = 0; i < 24; i++)
{
serialDataHex += sprintf(serialDataHex, "%02X", serialData[i]);
}
Firebase.RTDB.setString(&fbdo, SerialNo + "/Battery raw data", serialDataHex);
Firebase.RTDB.setString(&fbdo, SerialNo + "/Flag", flag);
if (flag == "0")
flag = "1";
else
flag = "0";
Serial.print("Firebase sent data = ");
Serial.println(serialDataHex);
}
}
}

String converter(uint8_t str)


{
return String((char *)str);
}

// Code of BLE MCU

#include <Arduino.h>
#include <iostream>
#include <string>
#if defined(ESP32)
#include <WiFi.h>
#include <FirebaseESP32.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#elif defined(PICO_RP2040)
#include <WiFi.h>
#include <FirebaseESP8266.h>
#endif // firebase library

// #define FIREBASE_HOST "smart-battery-17b25-default-rtdb.asia-southeast1.firebasedatabase.app"


// the project name address from firebase id

// #define FIREBASE_AUTH "wHIT29VSAGVB5Wh8GSWXM8C8ych7horLGlT5TsaN"


// the secret key generated from firebase
#define API_KEY "AIzaSyBktHAM1PkWUCM24Wik-EX7KaWj69_6Vas"

/* 3. Define the user Email to reset the password */


#define USER_EMAIL "USER_EMAIL"

/* 4. If work with RTDB, define the RTDB URL */


#define DATABASE_URL "smart-battery-17b25-default-rtdb.asia-southeast1.firebasedatabase.app"
//<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app

#define WIFI_SSID "hawk" // input your home or public wifi name

#define WIFI_PASSWORD "89061511"

String converter(uint8_t str);

// Define Firebase Data object


FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

bool dataComplete, dataComplete1, dataCompleteSend;


int deviceCounter, SelectedBattery, SelectedBatteryID;
uint8_t serialData[50], deviceManufaData[50];
String checkDataID, SerialNo = "", flag;

void setup()
{
Serial.begin(9600);
Serial2.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // try to connect with wifi


Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}

Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); // print local IP address
// Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the API key (required) */
config.api_key = API_KEY;

/* Assign the RTDB URL */


config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);

Serial.printf("Send Email reset password link... %s\n", Firebase.sendResetPassword(&config,


USER_EMAIL) ? "ok" : config.signer.resetPswError.message.c_str());
}
void loop()
{
if (dataComplete)
{
Serial.print(" data = ");
for (int i = 0; i < 24; i++)
{
Serial.print(serialData[i], HEX);
Serial.print(" ");
}
Serial.println();
dataComplete = false;
dataCompleteSend = true;
}
if (dataComplete1)
{
String devNames = "";
for (int i = 0; i < deviceCounter; i++)
{
Serial.println(deviceManufaData[i]);
devNames += deviceManufaData[i] + '.';
}
Firebase.RTDB.setString(&fbdo, "Devices", devNames);
deviceCounter = 0;
dataComplete1 = false;
}
SelectedBattery = Firebase.RTDB.getInt(&fbdo, "SelectedBattery");
if (SelectedBattery != 0 && SelectedBattery != 255)
{
SelectedBatteryID = deviceManufaData[SelectedBattery - 1];
Serial2.write("\nSel\n");
Serial2.write(SelectedBattery);
Firebase.RTDB.setInt(&fbdo, "SelectedBattery", -1);
}
if (SelectedBattery == 0)
{
Serial2.write("\nReset\n");
Serial2.write(1);
Firebase.RTDB.setInt(&fbdo, "Connect", 0);
Firebase.RTDB.setInt(&fbdo, "SelectedBattery", -1);
Firebase.RTDB.setString(&fbdo, "Devices", " ");
checkDataID = "";
}
if (Firebase.RTDB.getInt(&fbdo, "Reset"))
{
Serial2.write("\nReset\n");
Serial2.write(1);
Firebase.RTDB.setInt(&fbdo, "Connect", 0);
Firebase.RTDB.setInt(&fbdo, "Reset", 0);
Firebase.RTDB.setString(&fbdo, "Devices", " ");
}
int8_t BatteryCheck = Firebase.RTDB.getInt(&fbdo, SerialNo + "/BatteryCheck");
Serial.print("BatteryCheck = ");
Serial.println(BatteryCheck);
if (BatteryCheck == 1)
{
Serial2.write("\nHealth\n");
Serial2.write('d');
String stringData = SerialNo;
stringData += "/BatteryCheck";
Firebase.RTDB.setInt(&fbdo, stringData, 0);
}
if (dataCompleteSend)
{
dataCompleteSend = false;
Serial.print("Firebase Status = ");
// Serial.println(Firebase.ready);

uint8_t SerialNoConvert[2];
SerialNoConvert[0] = serialData[22];
SerialNoConvert[1] = serialData[23];
SerialNo = "90"; // + dataprintHEX(SerialNoConvert, 2);
for (int i = 0; i < 2; i++)
{
SerialNo += converter(SerialNoConvert[i]);
}
Serial.print("SerialNo = ");
Serial.println(SerialNo);

if (/*SelectedBatteryID == SerialNo &&*/ serialData[20] < 5)


{
String serialDataHex;
for (int i = 0; i < 24; i++)
{
// serialDataHex += sprintf(serialDataHex, "%02X", serialData[i]);
}
Firebase.RTDB.setString(&fbdo, SerialNo + "/Battery raw data", serialDataHex);
Firebase.RTDB.setString(&fbdo, SerialNo + "/Flag", flag);
if (flag == "0")
flag = "1";
else
flag = "0";
Serial.print("Firebase sent data = ");
Serial.println(serialDataHex);
}
}
}

String converter(uint8_t str)


{
return String((char *)str);
}

You might also like