-
Notifications
You must be signed in to change notification settings - Fork 28
/
Smart-BMS-Bluetooth-ESP32.ino
116 lines (100 loc) · 2.81 KB
/
Smart-BMS-Bluetooth-ESP32.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
Program to read out and display
data from xiaoxiang Smart BMS
over Bluetooth Low Energy
https://www.lithiumbatterypcb.com/
Tested with original BLE module provided.
Might work with generic BLE module when UUIDs are modified
Needs ESP32 and graphic display.
Tested on TTGO TS https://github.com/LilyGO/TTGO-TS
(c) Miroslav Kolinsky 2019
https://www.kolins.cz
thanks to Petr Jenik for big parts of code
thanks to Milan Petrzilka
known bugs:
-if BLE server is not available during startup, program hangs
-reconnection sort of works, sometimes ESP reboots
*/
#define eSPI 1
//#define oled 1
//#define TRACE commSerial.println(__FUNCTION__)
#define TRACE
#include <Arduino.h>
#include "BLEDevice.h"
#include "BLEScan.h" //why this is commented?
#include "mydatatypes.h"
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#ifdef eSPI
#include "TFT_eSPI.h"
#endif
#include <XPT2046_Touchscreen.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Wire.h>
#include "settings.h"
// #include <WiFi.h>
// #include <WiFiClient.h>
// #include <WebServer.h>
// #include <Update.h>
// #include "webpages.h"
HardwareSerial commSerial(0);
HardwareSerial bmsSerial(1);
//WebServer server(80);
//---- global variables ----
static boolean doConnect = false;
static boolean BLE_client_connected = false;
static boolean doScan = false;
packBasicInfoStruct packBasicInfo; //here shall be the latest data got from BMS
packEepromStruct packEeprom; //here shall be the latest data got from BMS
packCellInfoStruct packCellInfo; //here shall be the latest data got from BMS
const byte cBasicInfo3 = 3; //type of packet 3= basic info
const byte cCellInfo4 = 4; //type of packet 4= individual cell info
unsigned long previousMillis = 0;
unsigned long previousMillisl = 0;
const long myinterval = 5000;
const long interval = 4000;
bool toggle = false;
bool newPacketReceived = false;
int i = 0;
void setup() {
commSerial.begin(115200, SERIAL_8N1, 3, 1);
bmsSerial.begin(9600, SERIAL_8N1, 21, 22);
commSerial.println("Starting BMS dashboard application...");
// stripStartup();
// oled_startup();
lcdStartup();
// newtworkStartup();
commSerial.println("LCD fertig...");
bleStartup();
lcdclear();
showInfoLcd();
lcdwarte();
// linearMeter(99, 10, 310, 5, 10, 1, 30, 5);
// for (int wi = 0; wi <= 100; wi = wi + 5) {
// kreis(wi,120, 90,80,80);
// delay(500);
// }
}
//---------------------main loop------------------
void loop() {
//server.handleClient();
bleRequestData();
/*
if (newPacketReceived == true)
{
showInfoLcd();
printBasicInfo();
printCellInfo();
commSerial.println("-");
}
commSerial.print(".");
i++;
if (i > 60) {
i = 0;
commSerial.println();
}
*/
delay(1000);
}
//---------------------/ main loop------------------