ESP_IOT v2.5
IOT ESP Coding
BLEServerNetworking.cpp
Go to the documentation of this file.
1/**
2* \link BLEServerNetworking
3*/
4//
5// BLENetworking.cpp
6// M5Stick
7//
8// Created by Scott Moody on 1/19/22.
9//
10
11#include "BLEServerNetworking.h"
12#include <NimBLEDevice.h>
13#include "../../Defines.h"
14#define pettutorApproach
15//https://h2zero.github.io/esp-nimble-cpp/class_nim_b_l_e_device.html
16//!the BLE Server
17static NimBLEServer* _pBLEServer;
18NimBLECharacteristic* _pCharacteristic;
19
20//!device name
22
24
25//!need to device way to change these ...
26//#define SERVICE_UUID "B0E6A4BF-CCCC-FFFF-330C-0000000000F0" //Pet Tutor feeder service for feed
27//#define CHARACTERISTIC_UUID "B0E6A4BF-CCCC-FFFF-330C-0000000000F1" //Pet Tutor feeder characteristic
30
31#define MAX_MESSAGE 600
33
34
35//! retrieve the service name (PTFEEDER, PTFeeder:Name, PTClicker:Name, etc)
37{
39}
40
41#ifdef NOT_HERE_USE_MAIN
42//! 10.13.25 Nice day. Snow in Hills. Mt out, Tom and Marjarie
43//! call this now.. from main
44//!NOT CALLED...
45//!sets the device name in the advertising
46void setBLEServerDeviceName(char *deviceName)
47{
48 _pCharacteristic->setValue(deviceName);
49
50 //save the deviceName
51 _deviceName_BLEServer = deviceName;
52}
53#endif
54
55/** None of these are required as they will be handled by the library with defaults. **
56 ** Remove as you see fit for your needs */
57class BLEServeNetworkingCallbacks : public NimBLEServerCallbacks
58{
59 void onConnect(NimBLEServer* pServer)
60 {
61 SerialInfo.println("Client connected");
62 SerialInfo.println("Multi-connect support: start advertising");
63 NimBLEDevice::startAdvertising();
64 };
65 /** Alternative onConnect() method to extract details of the connection.
66 See: src/ble_gap.h for the details of the ble_gap_conn_desc struct.
67 */
68 void onConnect(NimBLEServer* pServer, ble_gap_conn_desc* desc)
69 {
70 SerialInfo.print("Client address: ");
71 SerialInfo.println(NimBLEAddress(desc->peer_ota_addr).toString().c_str());
72 /** We can use the connection handle here to ask for different connection parameters.
73 Args: connection handle, min connection interval, max connection interval
74 latency, supervision timeout.
75 Units; Min/Max Intervals: 1.25 millisecond increments.
76 Latency: number of intervals allowed to skip.
77 Timeout: 10 millisecond increments, try for 5x interval time for best results.
78 */
79 //GOOD:
80 pServer->updateConnParams(desc->conn_handle, 24, 48, 0, 60);
81
82 //try:
83 //pServer->updateConnParams(desc->conn_handle, 100, 200, 10, 160);
84
85 };
86 void onDisconnect(NimBLEServer* pServer)
87 {
88 SerialInfo.println("Client disconnected - start advertising");
89 NimBLEDevice::startAdvertising();
90 };
91 void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc)
92 {
93 SerialInfo.printf("MTU updated: %u for connection ID: %u\n", MTU, desc->conn_handle);
94 };
95
96 /********************* Security handled here **********************
97 ****** Note: these are the same return values as defaults ********/
98 uint32_t onPassKeyRequest()
99 {
100 SerialDebug.println("Server Passkey Request");
101 /** This should return a random 6 digit number for security
102 or make your own static passkey as done here.
103 */
104 return 123456;
105 };
106
107 bool onConfirmPIN(uint32_t pass_key)
108 {
109 SerialDebug.print("The passkey YES/NO number: "); SerialDebug.println(pass_key);
110 /** Return false if passkeys don't match. */
111 return true;
112 };
113
114 void onAuthenticationComplete(ble_gap_conn_desc* desc)
115 {
116 /** Check that encryption was successful, if not we disconnect the client */
117 if (!desc->sec_state.encrypted)
118 {
119 NimBLEDevice::getServer()->disconnect(desc->conn_handle);
120 SerialDebug.println("Encrypt connection failed - disconnecting client");
121 return;
122 }
123 SerialDebug.println("Starting BLE work!");
124 };
125};
126
127/** Handler class for characteristic actions */
128//!Note: the onRead and onWrite are from the perspective of the client. So onRead is the client calling this server, over BLE, and reading a value. The onWrite is the client writing to this server (sending a BLE message). This is where JSON or raw values are used.
129class BLEServerNetworkingCharacteristicCallbacks : public NimBLECharacteristicCallbacks
130{
131 //!called when wanting to "read" from this server
132 void onRead(NimBLECharacteristic* pCharacteristic)
133 {
134 SerialDebug.print(pCharacteristic->getUUID().toString().c_str());
135 SerialDebug.print(": onRead(), value: ");
136 // SerialDebug.print(_fullJSONString);
137 SerialDebug.println(pCharacteristic->getValue().c_str());
138 };
139
140 //!called when writing to the server.
141 void onWrite(NimBLECharacteristic* pCharacteristic)
142 {
143 SerialDebug.print(pCharacteristic->getUUID().toString().c_str());
144 SerialDebug.print(": onWrite(), value: ");
145// SerialDebug.println(pCharacteristic->getValue().c_str());
146// std::string rxValue = pCharacteristic->getValue().c_str();
147 //??
148 // ProcessClientCmd(rxValue[0]); //?? client sent a command now see what it is
149 // pCharacteristic->setValue(0x01); //?? This is the acknowlege(ACK) back to client. Later this should be contigent on a feed completed
150 /*******************************MQTT*************************************/
151 std::string value = pCharacteristic->getValue();
152 SerialDebug.println(value.c_str());
153
154 if (value.length() > 0) {
155 SerialDebug.println("*********");
156 SerialDebug.printf("New value: %d - \n", value.length());
157
158 //create a string 'ascii' from the values
159 for (int i = 0; i < value.length(); i++)
160 {
161 _asciiMessage[i] = value[i];
162 _asciiMessage[i + 1] = 0;
163 if (i >= value.length())
164 break;
165 }
166 SerialDebug.printf("_asciiMessage = '%s'\n", _asciiMessage);
167 //! try reboot...
168 if (strlen(_asciiMessage)>0 && _asciiMessage[0] == 'r')
169 {
170 //! reboot
171 SerialDebug.println(" **** REBOOT ***");
173 }
174 //reply right away .. see what happens..
175 //sendBLEMessageACKMessage();
176 //pCharacteristic->setValue(0x01); //?? This is the acknowlege(ACK) back to client. Later this should be contigent on a feed completed
177 SerialDebug.println(pCharacteristic->getUUID().toString().c_str());
178
179#ifdef TRY_LATER
180 //try .. #85
181 // if (value.compare("_ESP_32"==0))
182 {SerialInfo.println("pChar->setValue(_ESP_32)");
183 //send it back...
184 pCharacteristic->setValue((char*)"_ESP_32");
185 }
186#endif
187 //call the callback specified from the caller (eg. NimBLE_PetTutor_Server .. or others)
188 // (*_callbackFunction)(rxValue);
190
191#ifdef ESP_M5
192 SerialDebug.println("*** performing an M5 specific command from BLE trigger");
193 // do something ..
195
196 // M5.Beep.beep();
197
198 //!Increment the screen color 0..n cache for getting the screen color 0..max (max provided by sender)
199 //!This is implemented by incrementScreenColor_mainModule() since it knows the MAX value of colors
201
202
203#endif
204#ifdef NOT_NOW_MQTT_NETWORKING
205 //This should be a 'register' command..
206
207 // will return true if the message was JSON and was processes, false otherwise.
208 if (processJSONMessage(ascii))
209 {
210 //processed by the MQTTNetworking code..
211 pCharacteristic->setValue(0x01); //?? This is the acknowlege(ACK) back to client. Later this should be contigent on a feed completed
212 }
213 else
214 {
215 //perform feed...
216 SerialInfo.println("Perform FEED");
217
218 //std::string rxValue = pCharacteristic->getValue().c_str(); //??
219 //stepperModule_ProcessClientCmd(rxValue[0]); //?? client sent a command now see what it is
221 pCharacteristic->setValue(0x01); //?? This is the acknowlege(ACK) back to client. Later this should be contigent on a feed completed
222
223#ifdef ESP_M5
224
225//#ifdef TEST_M5_TO_M5
226 // do something ..
227 showText_displayModule("BLE FEED");
228
229 //!Increment the screen color 0..n cache for getting the screen color 0..max (max provided by sender)
230 //!This is implemented by incrementScreenColor_mainModule() since it knows the MAX value of colors
232
233//#endif
234#endif
235 }
236 SerialDebug.println("*********");
237
238#endif
239 }
240
241 /*******************************MQTT*************************************/
242
243 };
244
245 /** Called before notification or indication is sent,
246 the value can be changed here before sending if desired.
247 */
248 void onNotify(NimBLECharacteristic * pCharacteristic)
249 {
250 SerialDebug.println("Sending notification to clients");
251 };
252
253
254 /** The status returned in status is defined in NimBLECharacteristic.h.
255 The value returned in code is the NimBLE host return code.
256 */
257 void onStatus(NimBLECharacteristic * pCharacteristic, Status status, int code)
258 {
259#if (SERIAL_DEBUG_DEBUG)
260 String str = ("Notification/Indication status code: ");
261 str += status;
262 str += ", return code: ";
263 str += code;
264 str += ", ";
265 str += NimBLEUtils::returnCodeToString(code);
266 SerialDebug.println(str);
267#endif //serial_debug_debug
268 };
269
270 void onSubscribe(NimBLECharacteristic * pCharacteristic, ble_gap_conn_desc * desc, uint16_t subValue)
271 {
272#if (SERIAL_DEBUG_DEBUG)
273
274 String str = "Client ID: ";
275 str += desc->conn_handle;
276 str += " Address: ";
277 str += std::string(NimBLEAddress(desc->peer_ota_addr)).c_str();
278 if (subValue == 0) {
279 str += " Unsubscribed to ";
280 }
281 else if (subValue == 1) {
282 str += " Subscribed to notfications for ";
283 }
284 else if (subValue == 2) {
285 str += " Subscribed to indications for ";
286 }
287 else if (subValue == 3) {
288 str += " Subscribed to notifications and indications for ";
289 }
290 str += std::string(pCharacteristic->getUUID()).c_str();
291
292 SerialDebug.println(str);
293#endif //serial_debug_debug
294 };
295};
296
297/** Handler class for descriptor actions */
298class BLEServerNetworkingDescriptorCallbacks : public NimBLEDescriptorCallbacks
299{
300 void onWrite(NimBLEDescriptor* pDescriptor)
301 {
302#if (SERIAL_DEBUG_DEBUG)
303
304#define VERSION_1_4_1
305#ifdef VERSION_1_4_1
306 SerialDebug.print("Descriptor written value:");
307 SerialDebug.println(pDescriptor->getValue());
308#else
309 std::string dscVal((char*)pDescriptor->getValue(), pDescriptor->getLength());
310 SerialDebug.print("Descriptor written value:");
311 SerialDebug.println(dscVal.c_str());
312#endif
313
314#endif
315 };
316
317 void onRead(NimBLEDescriptor* pDescriptor)
318 {
319 SerialDebug.print(pDescriptor->getUUID().toString().c_str());
320 SerialDebug.println("Descriptor read");
321 SerialDebug.printf(" DeviceName = %s\n", _deviceName_BLEServer?_deviceName_BLEServer:"nil");
322 };
323};
324
325
326/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
327//static DescriptorCallbacks dscCallbacks;
328//static CharacteristicCallbacks chrCallbacks;
329
330
331/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
332static BLEServerNetworkingDescriptorCallbacks _descriptorBLEServerCallbacks;
333static BLEServerNetworkingCharacteristicCallbacks _characteristicBLEServerCallbacks;
334
335//!the 'loop' for this module BLEServerNetworking.
337{
338
339 // SerialDebug.printf("# Clients: %d \n\r", pServer->getConnectedCount()); // nimconfig.h can change the max clients allowed(up to 9). default is 3 wha
340#ifdef originalApproach
341 if (_pBLEServer->getConnectedCount()) {
342 NimBLEService* pSvc = pServer->getServiceByUUID("BAAD");
343 if (pSvc) {
344 NimBLECharacteristic* pChr = pSvc->getCharacteristic("F00D");
345 if (pChr) {
346 pChr->notify(true);
347 }
348 }
349 }
350#endif
351#ifdef pettutorApproach
352 if (_pBLEServer->getConnectedCount()) {
353 NimBLEService* pSvc = _pBLEServer->getServiceByUUID(_SERVICE_UUID);
354 if (pSvc) {
355 NimBLECharacteristic* pChr = pSvc->getCharacteristic(_CHARACTERISTIC_UUID);
356 if (pChr) {
357 pChr->notify(true);
358 }
359 }
360 }
361#endif
362}
363//!the 'setup' for this module BLEServerNetworking. Here the service name is added (and potentially more later)
364void setup_BLEServerNetworking(char *serviceName, char * deviceName, char *serviceUUID, char *characteristicUUID)
365{
366
367 _SERVICE_UUID = serviceUUID;
368 _CHARACTERISTIC_UUID = characteristicUUID;
369
370 SerialMin.printf("setup_BLEServerNetworking(%s,%s,%s,%s)\n", serviceName?serviceName:"NULL", deviceName?deviceName:"NULL", serviceUUID?serviceUUID:"NULL", characteristicUUID?characteristicUUID:"NULL");
371
372 char *storedDeviceName = deviceName_mainModule();
373 SerialTemp.printf("Stored DeviceName = '%s'\n", storedDeviceName);
374#define CALCULATE_BLE_NAME
375#ifdef CALCULATE_BLE_NAME
376 //! 10.13.25 copy here..
377 //! 8.16.25 (use the setting)
379 {
380 sprintf(_serviceName_BLEServer, "%s:%s", serviceName, storedDeviceName);
381 }
382 else
383 {
384 strcpy(_serviceName_BLEServer, serviceName);
385 }
386#else
387
388 if (strcmp(serviceName, "PTClicker")==0)
389 {
390 //! currently not using the option, just doing it...
391 sprintf(_serviceName_BLEServer, "%s:%s", serviceName, storedDeviceName);
392 }
393 else
394 {
395 //! 10.13.25 the service name was calaulated in MAIN already..
396 strcpy(_serviceName_BLEServer, serviceName);
397
398 //! 8.16.25 (use the setting)
400 {
401 sprintf(_serviceName_BLEServer, "%s:%s", serviceName, storedDeviceName);
402 }
403 else
404 {
405 strcpy(_serviceName_BLEServer, serviceName);
406 }
407 }
408#endif
409
410
411 SerialMin.printf("Setting BLE serviceName: '%s'\n", _serviceName_BLEServer);
412 // SerialMin.printf("LEN = %d\n", strlen(_serviceName_BLEServer));
413
414
415 //!! Seems to be a length of 31 too long
416 //! //DEBUG: crashed
417 // assert failed: static void NimBLEDevice::init(const string&) NimBLEDevice.cpp:901 (rc == 0)
418 // void NimBLEDevice::init(const std::string &deviceName) {
419 //!@see https://github.com/espressif/arduino-esp32/issues/7894
420 int len = strlen(_serviceName_BLEServer);
421 if (len > 29)
422 {
424 SerialMin.printf("Name was over 29 characters, so shirking: '%s'\n", _serviceName_BLEServer);
425 }
426
427
428 /** sets device name */
429 //??original NimBLEDevice::init("NimBLE-Arduino");
430 // NimBLEDevice::init("PTFeeder");
431 //NimBLEDevice::init(serviceName);
432 NimBLEDevice::init(_serviceName_BLEServer);
433
434 /** Optional: set the transmit power, default is 3db */
435 NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** +9db */
436
437 /** Set the IO capabilities of the device, each option will trigger a different pairing method.
438 BLE_HS_IO_DISPLAY_ONLY - Pass
439 \ng
440 */
441 //NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); // use passkey
442 //NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_YESNO); //use numeric comparison
443
444 /** 2 different ways to set security - both calls achieve the same result.
445 no bonding, no man in the middle protection, secure connections.
446
447 These are the default values, only shown here for demonstration.
448 */
449 //NimBLEDevice::setSecurityAuth(false, false, true);
450 NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
451 //** NOTE: DEAD is a hex string .. and BEEF is too, so they are not really strings but UUID's in HEX.
452
453 _pBLEServer = NimBLEDevice::createServer();
454 _pBLEServer->setCallbacks(new BLEServerCallbacks());
455 /****************** DEAD service BEEF characteristic 2904notify,R/W/W_ENC(pairing REQUIRED!) ********************/
456 NimBLEService* pDeadService = _pBLEServer->createService("DEAD");
457 //?? NimBLEService* pDeadService = pServer->createService(SERVICE_UUID);
458 NimBLECharacteristic* pBeefCharacteristic = pDeadService->createCharacteristic(
459 "BEEF",
460 //?? NimBLECharacteristic * pBeefCharacteristic = pDeadService->createCharacteristic(
461 //?? CHARACTERISTIC_UUID,
462 NIMBLE_PROPERTY::READ |
463 NIMBLE_PROPERTY::WRITE |
464 /** Require a secure connection for read and write access */
465 NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted
466 NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted
467 );
468 //NOTE: IS THIS RIGHT? vs the other characteristic?? 5.19.22
469 //assign to global: It's the Food charactestic..
470#ifdef OLD_BLE_NO_ACK_APPROACH
471 _pCharacteristic = pBeefCharacteristic;
472#endif
473
474
475
476 /*******************************MQTT*************************************/
477 //#ifdef MQTT_NETWORKING
478 pBeefCharacteristic->setValue(deviceName);
479
480 //#else
481 // pBeefCharacteristic->setValue("Burger");
482 //#endif
483 /*******************************MQTT*************************************/
484
485 pBeefCharacteristic->setCallbacks(&_characteristicBLEServerCallbacks);
486
487 /** 2904 descriptors are a special case, when createDescriptor is called with
488 0x2904 a NimBLE2904 class is created with the correct properties and sizes.
489 However we must cast the returned reference to the correct type as the method
490 only returns a pointer to the base NimBLEDescriptor class.
491 */
492 NimBLE2904* pBeef2904 = (NimBLE2904*)pBeefCharacteristic->createDescriptor("2904");
493 pBeef2904->setFormat(NimBLE2904::FORMAT_UTF8);
494 pBeef2904->setCallbacks(&_descriptorBLEServerCallbacks);
495
496 /******** BAAD service F00D characteristic R/W/N C01D Descriptor ********************************/
497#ifdef originalApproach
498 NimBLEService* pBaadService = pServer->createService("BAAD");
499 NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic(
500 "F00D",
501 NIMBLE_PROPERTY::READ |
502 NIMBLE_PROPERTY::WRITE |
503 NIMBLE_PROPERTY::NOTIFY
504 );
505#endif
506#ifdef pettutorApproach
507 NimBLEService* pBaadService = _pBLEServer->createService(_SERVICE_UUID);
508 NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic(
510 NIMBLE_PROPERTY::READ |
511 NIMBLE_PROPERTY::WRITE // |
512 // NIMBLE_PROPERTY::NOTIFY
513 );
514#endif
515
516#ifdef originalApproach
517 pFoodCharacteristic->setValue("Fries");
518#endif
519
520 pFoodCharacteristic->setCallbacks(&_characteristicBLEServerCallbacks);
521
522 /** Note a 0x2902 descriptor MUST NOT be created as NimBLE will create one automatically
523 if notification or indication properties are assigned to a characteristic.
524 */
525
526#ifdef originalApproach
527 /** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */
528 NimBLEDescriptor* pC01Ddsc = pFoodCharacteristic->createDescriptor(
529 "C01D",
530 NIMBLE_PROPERTY::READ |
531 NIMBLE_PROPERTY::WRITE |
532 NIMBLE_PROPERTY::WRITE_ENC, // only allow writing if paired / encrypted
533 20
534 );
535 pC01Ddsc->setValue("Send it back!");
536 pC01Ddsc->setCallbacks(&dscCallbacks);
537#endif
538#ifdef pettutorApproach
539 /** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */
540 NimBLEDescriptor* pPetTutordsc = pFoodCharacteristic->createDescriptor(
541 "C01D", //the UUID is 0xC01D
542 NIMBLE_PROPERTY::READ |
543 NIMBLE_PROPERTY::WRITE |
544 20
545 );
546 pPetTutordsc->setValue("feed s/a/j type u/m ");
547 pPetTutordsc->setCallbacks(&_descriptorBLEServerCallbacks);
548#endif
549
550#ifdef CURRENT_BLE_ACK_APPROACH
551 //THIS IS RIGHT characteristic
552 _pCharacteristic = pFoodCharacteristic;
553 // end setup of services and characteristics
554#endif
555
556//#define TRY_THIRD_SERVICE_WITH_NAME
557#ifdef TRY_THIRD_SERVICE_WITH_NAME
558#define DEVICE_NAME_UUID "53636F74-7479426F79" //ScottyBoy
559#define DEVICE_NAME_SERVICE "6E616D65" //name
560 /****************** DEAD service BEEF characteristic 2904notify,R/W/W_ENC(pairing REQUIRED!) ********************/
561 NimBLEService* pNameService = _pBLEServer->createService(DEVICE_NAME_SERVICE);
562 //?? NimBLEService* pDeadService = pServer->createService(SERVICE_UUID);
563 NimBLECharacteristic* pNameCharacteristic = pNameService->createCharacteristic(
564 DEVICE_NAME_UUID,
565 //?? NimBLECharacteristic * pBeefCharacteristic = pDeadService->createCharacteristic(
566 //?? CHARACTERISTIC_UUID,
567 NIMBLE_PROPERTY::READ |
568 NIMBLE_PROPERTY::WRITE |
569 /** Require a secure connection for read and write access */
570 NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted
571 NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted
572 );
573
574
575 /*******************************MQTT*************************************/
576 //#ifdef MQTT_NETWORKING
577 pNameCharacteristic->setValue(deviceName);
578
579 //#else
580 // pBeefCharacteristic->setValue("Burger");
581 //#endif
582 /*******************************MQTT*************************************/
583
584 pNameCharacteristic->setCallbacks(&_characteristicBLEServerCallbacks);
585
586 /** 2904 descriptors are a special case, when createDescriptor is called with
587 0x2904 a NimBLE2904 class is created with the correct properties and sizes.
588 However we must cast the returned reference to the correct type as the method
589 only returns a pointer to the base NimBLEDescriptor class.
590 */
591 NimBLE2904* pName2904 = (NimBLE2904*)pNameCharacteristic->createDescriptor("2904");
592 pName2904->setFormat(NimBLE2904::FORMAT_UTF8);
593 pName2904->setCallbacks(&_descriptorBLEServerCallbacks);
594 pNameService->start();
595
596#endif
597
598 /** Start the services when finished creating all Characteristics and Descriptors */
599 pDeadService->start();
600 pBaadService->start();
601
602 NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
603 /** Add the services to the advertisment data **/
604 pAdvertising->addServiceUUID(pDeadService->getUUID());
605 pAdvertising->addServiceUUID(pBaadService->getUUID());
606 /** If your device is battery powered you may consider setting scan response
607 to false as it will extend battery life at the expense of less data sent.
608 */
609#ifdef TRY_THIRD_SERVICE_WITH_NAME
610 pAdvertising->addServiceUUID(pNameService->getUUID());
611
612#endif
613 pAdvertising->setScanResponse(true);
614 pAdvertising->start();
615 //try the user supplied local name: Local Name == ScottyBoy in Advertisment
616// char *storedDeviceName = deviceName_mainModule();
617// SerialTemp.print("Stored DeviceName = ");
618// SerialTemp.println(storedDeviceName);
619 //!setName shows up ad LocalName in Punchthrough Scanner, but
620 // pAdvertising->setName(storedDeviceName);
621
622
623 SerialInfo.println("Advertising Started");
624}
625
626
627//!send ACK over bluetooth, this right now is 0x01
629{
630 SerialTemp.printf("%d sendBLEMessageACKMessage._pCharacteristic\n", _pCharacteristic);
631 _pCharacteristic->setValue(0x01); //?? This is the acknowlege(ACK) back to client. Later this should be contigent on a feed completed
632}
633
634
void loop_BLEServerNetworking()
the 'loop' for this module BLEServerNetworking.
#define MAX_MESSAGE
void sendBLEMessageACKMessage()
send ACK over bluetooth, this right now is 0x01
char _asciiMessage[MAX_MESSAGE]
char * getServiceName_BLEServerNetworking()
retrieve the service name (PTFEEDER, PTFeeder:Name, PTClicker:Name, etc)
char * _CHARACTERISTIC_UUID
NimBLECharacteristic * _pCharacteristic
char * _SERVICE_UUID
need to device way to change these ...
char * _deviceName_BLEServer
device name
void setup_BLEServerNetworking(char *serviceName, char *deviceName, char *serviceUUID, char *characteristicUUID)
the 'setup' for this module BLEServerNetworking. Here the service name is added (and potentially more...
char _serviceName_BLEServer[100]
#define BLE_SERVER_CALLBACK_ONWRITE
void addToTextMessages_displayModule(String text)
void incrementScreenColor_displayModule()
void showText_displayModule(String text)
char * deviceName_mainModule()
gets the device name
#define CALLBACKS_BLE_SERVER
Definition: MainModule.cpp:711
void processClientCommandChar_mainModule(char cmd)
single character version of processClientCommand (since many used that already)
void rebootDevice_mainModule()
void callCallbackMain(int callbacksModuleId, int callbackType, char *message)
performs the indirect callback based on the callbackType
Definition: MainModule.cpp:819
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
#define PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING
if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
Note: the onRead and onWrite are from the perspective of the client. So onRead is the client calling ...