Showing 4 changed files with 33 additions and 5 deletions
+5 -1
BLE_iBeacon.ino
... ...
@@ -39,7 +39,7 @@
39 39
 #include "serial.h"
40 40
 
41 41
 #include <EEPROM.h>
42
-#define EEPROM_SIZE 1 // To save BeaconType upon restart
42
+#define EEPROM_SIZE 3 // To save BeaconType upon restart
43 43
 
44 44
 //#define DISABLE_BT //For Battery charging test
45 45
 //#define DEBUG_PAYLOAD //TO print the payload to be sent
... ...
@@ -179,6 +179,10 @@ void loop() {
179 179
 
180 180
   beacon_count++;
181 181
 
182
+  uint32_t storedNum = ( EEPROM.read(1) << 8 ) + EEPROM.read(2);
183
+  beacon_num[0] = ((storedNum >> 8) & 0xff );
184
+  beacon_num[1] = (storedNum & 0xff );
185
+
182 186
   #ifndef DISABLE_BT
183 187
   // Create the BLE Server
184 188
   pAdvertising = BLEDevice::getAdvertising();
+2 -2
beacon.h
... ...
@@ -2,10 +2,10 @@
2 2
 #define _BEACON_H
3 3
 
4 4
 #define BEACON_SLEEP_ADV 2000 //1.0s between uptime
5
-#define BEACON_ADV_DURATION 400 //400ms
5
+#define BEACON_ADV_DURATION 500 //400ms
6 6
 #define BEACON_UUID         "7c8a68a6-ddd0-11e9-8a34-2a2ae2dbcce4"
7 7
 #define BEACON_SERVICE_UUID "feaa"
8
-#define BEACON_NAME         "FakeESP"
8
+#define BEACON_NAME         "Eddy"
9 9
 enum EN_BEACON_TYPE {
10 10
   EN_BEACON_TYPE_entry = 0x01,
11 11
   EN_BEACON_TYPE_exit = 0x02,
+2 -2
display.h
... ...
@@ -51,7 +51,7 @@ float getBatteryLevel(void)
51 51
 void DisplayButtonStatus() {
52 52
   #ifdef ARDUINO_HELTEC_WIFI_LORA_32
53 53
   Heltec.display->clear();
54
-  Heltec.display->drawString(0, LINE1, "BT: "+String(macStr));
54
+  Heltec.display->drawString(0, LINE1, "EDDY: "+String(macStr));
55 55
   Heltec.display->drawString(0, LINE2, "I : "+String(instanceStr));
56 56
   Heltec.display->drawString(0, LINE4, beaconTypeStr);
57 57
   Heltec.display->drawString(0, LINEBOTTOM, "Cnt: "+String(beacon_count));
... ...
@@ -63,7 +63,7 @@ void DisplayButtonStatus() {
63 63
   #elif ARDUINO_M5Stick_C //ARDUINO_TTGO_LoRa32_V1
64 64
   //M5.Lcd.fillScreen(BLACK);
65 65
   M5.Lcd.setTextColor(0x7bef, BLACK);
66
-  M5.Lcd.setCursor(0, LINE1, 1);M5.Lcd.println("BT: "+String(macStr));
66
+  M5.Lcd.setCursor(0, LINE1, 1);M5.Lcd.println("EDDY: "+String(macStr));
67 67
   M5.Lcd.setCursor(0, LINE2, 1);M5.Lcd.println("I : "+String(instanceStr));
68 68
   M5.Lcd.fillRect(0, LINE4, 160, 15, BLACK);
69 69
   M5.Lcd.setCursor(0, LINE4, 2);M5.Lcd.setTextColor(GREEN, BLACK);  M5.Lcd.println(beaconTypeStr);
+24
serial.h
... ...
@@ -9,6 +9,7 @@ void serialHelp() {
9 9
   Serial.println("- help: Display this screen");
10 10
   Serial.println("- beacon: Display beacon details");
11 11
   Serial.println("- type X: Set type of Beacon");
12
+  Serial.println("- num aabb: Set the Beacon number in HEX padded to 2bytes");
12 13
 }
13 14
 
14 15
 void serialBeacon() {
... ...
@@ -22,6 +23,27 @@ void serialBeacon() {
22 23
   Serial.println(serialOut);
23 24
 }
24 25
 
26
+void serialNum(char *buf) {
27
+  int len = strlen(buf);
28
+  char newNum[5]="";
29
+  strncpy(newNum,buf+4,4);
30
+  newNum[4] =0x0;
31
+  String newNumStr = "";
32
+  newNumStr += newNum;
33
+  Serial.println(newNumStr);
34
+  uint16_t newNumDW = strtoul(newNum,NULL,16);
35
+  EEPROM.write(1, (uint8_t)((newNumDW >> 8) & 0xff) );
36
+  EEPROM.write(2, (uint8_t)(newNumDW & 0xff) );
37
+  EEPROM.commit();
38
+  beacon_num[0] = EEPROM.read(1);
39
+  beacon_num[1] = EEPROM.read(2);
40
+  String serialOut = "{\"command\": \"num\", \"status\": { ";
41
+  serialOut += "\"numDec\": \""+String(newNumDW)+"\", ";
42
+  serialOut += "\"numHex\": \""+String(newNum)+"\"";
43
+  serialOut += "}";
44
+  Serial.println(serialOut);
45
+}
46
+
25 47
 void serialType(EN_BEACON_TYPE type) {
26 48
   beacon_type = type;
27 49
   switch( type ) {
... ...
@@ -73,6 +95,8 @@ void pollSerial() {
73 95
       serialType(EN_BEACON_TYPE_safe);
74 96
     } else if( 0 == strcmp(command,"type 5") ) {
75 97
       serialType(EN_BEACON_TYPE_other);
98
+    } else if( 0 == strncmp(command,"num ",4) ) {
99
+      serialNum(command);
76 100
     } else {
77 101
       Serial.println("{\"command\": \""+String(command)+"\", \"status\": \"error\" }");
78 102
     }