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