{"id":3581,"date":"2023-09-09T06:50:00","date_gmt":"2023-09-09T13:50:00","guid":{"rendered":"https:\/\/www.donluc.com\/?p=3581"},"modified":"2023-09-09T06:50:00","modified_gmt":"2023-09-09T13:50:00","slug":"project-26-radio-frequency-bluetooth-server-and-client-mk26","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=3581","title":{"rendered":"Project #26 &#8211; Radio Frequency &#8211; Bluetooth Server and Client &#8211; Mk26"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3581-1\" width=\"720\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07W.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07W.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07W.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#DonLucElectronics #DonLuc #RadioFrequency #Bluetooth #Display #SparkFun #BME280 #CCS811 #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07a.png\" alt=\"Bluetooth Server and Client\" width=\"720\" height=\"591\" class=\"alignnone size-full wp-image-3583\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07a-300x246.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07b.png\" alt=\"Bluetooth Server and Client\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3584\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07b-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07c.png\" alt=\"Bluetooth Server and Client\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3585\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/09\/DL2307Mk07c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;-<\/p>\n<p><strong>Bluetooth Server and Client<\/strong><\/p>\n<p>Connect the SparkFun BME280 and CCS811 this is the &#8220;Server&#8221; board. Upload SparkFun Thing Plus the Server code to the board using the USB cable. When uploading is complete, disconnect this board from the computer. Now, connect the Lithium Ion battery to the &#8220;Server&#8221;. Next, connect the second SparkFun Thing Plus to your computer and upload the Client code to the board. We have two Arduino sketches to upload to the SparkFun Thing Plus boards. Upload the first sketch to the Server SparkFun Thing Plus and the second sketch to the Client SparkFun Thing Plus.<\/p>\n<p><strong>DL2307Mk07<\/strong><\/p>\n<p>2 x SparkFun Thing Plus &#8211; ESP32 WROOM<br \/>\n1 x SparkFun BME280 &#8211; Temperature, Humidity, Barometric Pressure, and Altitude<br \/>\n1 x SparkFun Air Quality Breakout &#8211; CCS811<br \/>\n1 x Adafruit SHARP Memory Display Breakout<br \/>\n2 x Lithium Ion Battery &#8211; 850mAh<br \/>\n2 x SparkFun Cerberus USB Cable<\/p>\n<p><strong>SparkFun Thing Plus &#8211; ESP32 WROOM (Server)<\/strong><\/p>\n<p>LED &#8211; LED_BUILTIN<br \/>\nSDA &#8211; Digital 23<br \/>\nSCL &#8211; Digital 22<br \/>\nRX2 &#8211; Bluetooth<br \/>\nTX2 &#8211; Bluetooth<br \/>\nVIN &#8211; +3.3V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>DL2307Mk07ps.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/* ***** Don Luc Electronics \u00a9 *****\r\nSoftware Version Information\r\nProject #26 - Radio Frequency - Bluetooth Server and Client - Mk26\r\n26-26\r\nDL2307Mk07ps.ino\r\n2 x SparkFun Thing Plus - ESP32 WROOM\r\n1 x SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\n1 x SparkFun Air Quality Breakout - CCS811\r\n1 x Adafruit SHARP Memory Display Breakout\r\n2 x Lithium Ion Battery - 850mAh\r\n2 x SparkFun Cerberus USB Cable\r\n*\/\r\n\r\n\/\/ Include the Library Code\r\n\/\/ BLE Device\r\n#include &lt;BLEDevice.h&gt;\r\n\/\/ BLE Utils\r\n#include &lt;BLEUtils.h&gt;\r\n\/\/ BLE Serve\r\n#include &lt;BLEServer.h&gt;\r\n\/\/ Two Wire Interface (TWI\/I2C)\r\n#include &lt;Wire.h&gt;\r\n\/\/ SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\n#include &lt;SparkFunBME280.h&gt;\r\n\/\/ SparkFun CCS811 - eCO2 &amp; tVOC\r\n#include &lt;SparkFunCCS811.h&gt;\r\n\r\n\/\/ See the following for generating UUIDs:\r\n\/\/ https:\/\/www.uuidgenerator.net\/\r\n#define SERVICE_UUID            &quot;7c394dc4-49a8-4c22-8a5b-b1612d8c13c1&quot;\r\n#define CHARACTERISTIC_UUID     &quot;a4c4cec2-f394-4f7a-b9de-89047feca74b&quot;\r\n#define CHARACTERISTIC_TEM_UUID &quot;74bd92c6-89d0-4387-823e-97e7e0fb7a2b&quot;\r\n#define CHARACTERISTIC_HUM_UUID &quot;1b63f246-b97f-4d2e-b8eb-f69e20a23a34&quot;\r\n#define CHARACTERISTIC_BAR_UUID &quot;43788175-37a7-4280-93c6-c690324d088e&quot;\r\n#define CHARACTERISTIC_ALT_UUID &quot;609deed9-a72d-45c3-aaba-14a73b0d8fda&quot;\r\n#define CHARACTERISTIC_ECO_UUID &quot;ab17aace-c0b9-4bd3-bb93-7715d9afaeea&quot;\r\n#define CHARACTERISTIC_VOC_UUID &quot;6a8bf86a-9d40-457c-9f7f-f13a3d6803f1&quot;\r\n\/\/ Makes the chracteristic globlal\r\nstatic BLECharacteristic *pCharacteristicTEM;\r\nstatic BLECharacteristic *pCharacteristicHUM;\r\nstatic BLECharacteristic *pCharacteristicBAR;\r\nstatic BLECharacteristic *pCharacteristicALT;\r\nstatic BLECharacteristic *pCharacteristicECO;\r\nstatic BLECharacteristic *pCharacteristicVOC;\r\n\r\n\/\/ SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\nBME280 myBME280;\r\nfloat BMEtempC = 0;\r\nfloat BMEhumid = 0;\r\nfloat BMEpressure = 0;\r\nfloat BMEaltitudeM = 0;\r\nString FullString = &quot;&quot;;\r\n\r\n\/\/ SparkFun CCS811 - eCO2 &amp; tVOC\r\n\/\/ Default I2C Address\r\n#define CCS811_ADDR 0x5B \r\nCCS811 myCCS811(CCS811_ADDR);\r\nfloat CCS811CO2 = 0;\r\nfloat CCS811TVOC = 0;\r\nString FullStringA = &quot;&quot;;\r\n\r\n\/\/ Software Version Information\r\nString sver = &quot;26-26&quot;;\r\n\r\nvoid loop() {\r\n\r\n  \/\/ SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\n  isBME280();\r\n\r\n  \/\/ SparkFun CCS811 - eCO2 &amp; tVOC\r\n  isCCS811();\r\n\r\n  \/\/ Delay 1 sec\r\n  delay(1000);\r\n\r\n}\r\n<\/pre>\n<p><strong>getBME280.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\n\/\/ isBME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\nvoid isBME280(){\r\n\r\n  \/\/ Temperature Celsius\r\n  BMEtempC = myBME280.readTempC();\r\n  \/\/ Humidity\r\n  BMEhumid = myBME280.readFloatHumidity();\r\n  \/\/ Barometric Pressure\r\n  BMEpressure = myBME280.readFloatPressure();\r\n  \/\/ Altitude Meters\r\n  BMEaltitudeM = (myBME280.readFloatAltitudeMeters(), 2);\r\n\r\n  \/\/ setValue takes uint8_t, uint16_t, uint32_t, int, float, double and string\r\n  pCharacteristicTEM-&gt;setValue(BMEtempC);\r\n  pCharacteristicHUM-&gt;setValue(BMEhumid);\r\n  pCharacteristicBAR-&gt;setValue(BMEpressure);\r\n  pCharacteristicALT-&gt;setValue(BMEaltitudeM);\r\n\r\n  \/\/ FullString\r\n  FullString = &quot;Temperature = &quot; + String(BMEtempC,2) + &quot; Humidity = &quot;\r\n  + String(BMEhumid,2) + &quot; Barometric = &quot; + String(BMEpressure,2) \r\n  + &quot; Altitude Meters = &quot; + String(BMEaltitudeM,2) + &quot;\\r\\n&quot;;\r\n\r\n  \/\/ FullString Bluetooth Serial + Serial\r\n  for(int i = 0; i &lt; FullString.length(); i++)\r\n  {\r\n\r\n    \/\/ Serial\r\n    Serial.write(FullString.c_str()[i]);\r\n    \r\n  }\r\n\r\n}\r\n<\/pre>\n<p><strong>getCCS811.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ CCS811 - eCO2 &amp; tVOC\r\n\/\/ isCCS811 - eCO2 &amp; tVOC\r\nvoid isCCS811(){\r\n\r\n  \/\/ This sends the temperature &amp; humidity data to the CCS811\r\n  myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);\r\n\r\n  \/\/ Calling this function updates the global tVOC and eCO2 variables\r\n  myCCS811.readAlgorithmResults();\r\n\r\n  \/\/ eCO2 Concentration\r\n  CCS811CO2 = myCCS811.getCO2();\r\n  \r\n  \/\/ tVOC Concentration\r\n  CCS811TVOC = myCCS811.getTVOC();\r\n\r\n  \/\/ setValue takes uint8_t, uint16_t, uint32_t, int, float, double and string\r\n  pCharacteristicECO-&gt;setValue(CCS811CO2);\r\n  pCharacteristicVOC-&gt;setValue(CCS811TVOC);\r\n\r\n  \/\/ FullStringA\r\n  FullStringA = &quot;TVOCs = &quot; + String(CCS811TVOC,2) + &quot; eCO2 = &quot;\r\n  + String(CCS811CO2,2) + &quot;\\r\\n&quot;;\r\n\r\n  \/\/ FullStringA Bluetooth Serial + Serial\r\n  for(int i = 0; i &lt; FullStringA.length(); i++)\r\n  {\r\n\r\n    \/\/ Serial\r\n    Serial.write(FullStringA.c_str()[i]);\r\n    \r\n  }\r\n\r\n\r\n}\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Setup\r\nvoid setup()\r\n{\r\n  \r\n  \/\/ Serial Begin\r\n  Serial.begin(115200);\r\n  Serial.println(&quot;Starting BLE work!&quot;);\r\n\r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n  \r\n  \/\/ Wire - Inialize I2C Hardware\r\n  Wire.begin();\r\n\r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n\r\n  \/\/ SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude \r\n  myBME280.begin();\r\n\r\n  \/\/ CCS811 - eCO2 &amp; tVOC\r\n  myCCS811.begin();\r\n\r\n  \/\/ Initialize digital pin LED_BUILTIN as an output\r\n  pinMode(LED_BUILTIN, OUTPUT);\r\n  \/\/ Turn the LED on HIGH\r\n  digitalWrite(LED_BUILTIN, HIGH);\r\n\r\n  \/\/ BLE Device Init\r\n  BLEDevice::init(&quot;Don Luc Electronics Server&quot;);\r\n  BLEServer *pServer = BLEDevice::createServer();\r\n  BLEService *pService = pServer-&gt;createService(SERVICE_UUID);\r\n  BLECharacteristic *pCharacteristic = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n\r\n  pCharacteristicTEM = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_TEM_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n                                       \r\n  pCharacteristicHUM = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_HUM_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n  \r\n  pCharacteristicBAR = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_BAR_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n  \r\n  pCharacteristicALT = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_ALT_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n  \r\n  pCharacteristicVOC = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_VOC_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n  \r\n  pCharacteristicECO = pService-&gt;createCharacteristic(\r\n                                         CHARACTERISTIC_ECO_UUID,\r\n                                         BLECharacteristic::PROPERTY_READ |\r\n                                         BLECharacteristic::PROPERTY_WRITE\r\n                                       );\r\n  \r\n  pCharacteristic-&gt;setValue(&quot;Luc Paquin&quot;);\r\n  pService-&gt;start();\r\n\r\n  \/\/ This still is working for backward compatibility\r\n  \/\/ BLEAdvertising *pAdvertising = pServer-&gt;getAdvertising();\r\n  \/\/ BLE Advertising\r\n  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();\r\n  pAdvertising-&gt;addServiceUUID(SERVICE_UUID);\r\n  pAdvertising-&gt;setScanResponse(true);\r\n  \/\/ Functions that help with iPhone connections issue\r\n  pAdvertising-&gt;setMinPreferred(0x06);\r\n  pAdvertising-&gt;setMinPreferred(0x12);\r\n  BLEDevice::startAdvertising();\r\n\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>SparkFun Thing Plus &#8211; ESP32 WROOM (Client)<\/strong><\/p>\n<p>LED &#8211; Digital 21<br \/>\nSCK &#8211; Digital 13<br \/>\nMOSI &#8211; Digital 12<br \/>\nSS &#8211; Digital 27<br \/>\nRX2 &#8211; Bluetooth<br \/>\nTX2 &#8211; Bluetooth<br \/>\nVIN &#8211; +3.3V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>DL2307Mk07pr.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/* ***** Don Luc Electronics \u00a9 *****\r\nSoftware Version Information\r\nProject #26 - Radio Frequency - Bluetooth Server and Client - Mk26\r\n26-26\r\nDL2307Mk07pr.ino\r\n2 x SparkFun Thing Plus - ESP32 WROOM\r\n1 x SparkFun BME280 - Temperature, Humidity, Barometric Pressure, and Altitude\r\n1 x SparkFun Air Quality Breakout - CCS811\r\n1 x Adafruit SHARP Memory Display Breakout\r\n2 x Lithium Ion Battery - 850mAh\r\n2 x SparkFun Cerberus USB Cable\r\n*\/\r\n\r\n\/\/ Include the Library Code\r\n\/\/ Bluetooth BLE Device\r\n#include &quot;BLEDevice.h&quot;\r\n\/\/ SHARP Memory Display\r\n#include &lt;Adafruit_SharpMem.h&gt;\r\n\/\/ Adafruit GFX Library\r\n#include &lt;Adafruit_GFX.h&gt;\r\n\r\n\/\/ SHARP Memory Display\r\n\/\/ any pins can be used\r\n#define SHARP_SCK  13\r\n#define SHARP_MOSI 12\r\n#define SHARP_SS   27\r\n\/\/ Set the size of the display here, e.g. 144x168!\r\nAdafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);\r\n\/\/ The currently-available SHARP Memory Display (144x168 pixels)\r\n\/\/ requires &gt; 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno\r\n\/\/ or other &lt;4K &quot;classic&quot; devices.\r\n#define BLACK 0\r\n#define WHITE 1\r\n\/\/ 1\/2 of lesser of display width or height\r\nint minorHalfSize;\r\n\r\n\/\/ The remote service we wish to connect to.\r\nstatic BLEUUID serviceUUID(&quot;7c394dc4-49a8-4c22-8a5b-b1612d8c13c1&quot;);\r\n\/\/ The characteristic of the remote service we are interested in.\r\nstatic BLEUUID    charUUID(&quot;a4c4cec2-f394-4f7a-b9de-89047feca74b&quot;);\r\n\/\/ Use the same UUID as on the server\r\nstatic BLEUUID    charTEMUUID(&quot;74bd92c6-89d0-4387-823e-97e7e0fb7a2b&quot;);\r\nstatic BLEUUID    charHUMUUID(&quot;1b63f246-b97f-4d2e-b8eb-f69e20a23a34&quot;);\r\nstatic BLEUUID    charBARUUID(&quot;43788175-37a7-4280-93c6-c690324d088e&quot;);\r\nstatic BLEUUID    charALTUUID(&quot;609deed9-a72d-45c3-aaba-14a73b0d8fda&quot;);\r\nstatic BLEUUID    charECOUUID(&quot;ab17aace-c0b9-4bd3-bb93-7715d9afaeea&quot;);\r\nstatic BLEUUID    charVOCUUID(&quot;6a8bf86a-9d40-457c-9f7f-f13a3d6803f1&quot;);\r\nstatic boolean doConnect = false;\r\nstatic boolean connected = false;\r\nstatic boolean doScan = false;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristic;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicTEM;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicHUM;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicBAR;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicALT;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicECO;\r\nstatic BLERemoteCharacteristic* pRemoteCharacteristicVOC;\r\n\r\nstatic BLEAdvertisedDevice* myDevice;\r\nfloat TEMValue;\r\nfloat HUMValue;\r\nfloat BARValue;\r\nfloat ALTValue;\r\nfloat ECOValue;\r\nfloat VOCValue;\r\n\r\nint iLED = 21;\r\n\r\n\/\/ Software Version Information\r\nString sver = &quot;26-26&quot;;\r\n\r\nvoid loop() {\r\n\r\n  isBluetoothBLE();\r\n\r\n  isDisplayEnvironmental();\r\n \r\n}\r\n<\/pre>\n<p><strong>getBluetoothBLE.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Bluetooth BLE\r\nvoid isBluetoothBLE(){\r\n\r\n  \/\/ If the flag &quot;doConnect&quot; is true then we have scanned for \r\n  \/\/ and found the desired\r\n  \/\/ BLE Server with which we wish to connect.  Now we connect to it.\r\n  \/\/ Once we are connected we set the connected flag to be true.\r\n  if (doConnect == true) {\r\n    if (connectToServer()) {\r\n      Serial.println(&quot;We are now connected to the BLE Server.&quot;);\r\n    } else {\r\n      Serial.println(&quot;We have failed to connect to the server; there is nothin more we will do.&quot;);\r\n    }\r\n    doConnect = false;\r\n  }\r\n\r\n  \/\/ If we are connected to a peer BLE Server, update the characteristic each time we are reached\r\n  \/\/ with the current time since boot.\r\n  if (connected) {\r\n    String newValue = &quot;Time since boot: &quot; + String(millis()\/1000);\r\n    \/\/Serial.println(&quot;Setting new characteristic value to \\&quot;&quot; + newValue + &quot;\\&quot;&quot;);\r\n\r\n    \/\/ Set the characteristic&#039;s value to be the array of bytes that is actually a string.\r\n   \/\/ pRemoteCharacteristic-&gt;writeValue(newValue.c_str(), newValue.length());\/\/***********JKO\r\n  }else if(doScan){\r\n    BLEDevice::getScan()-&gt;start(0);  \/\/ this is just example to start scan after disconnect, most likely there is better way to do it in arduino\r\n  }\r\n\r\n  \/\/ read the Characteristics and store them in a variable\r\n  \/\/ This also makes the print command do float handling\r\n  TEMValue = pRemoteCharacteristicTEM-&gt;readFloat();\r\n  HUMValue = pRemoteCharacteristicHUM-&gt;readFloat();\r\n  BARValue = pRemoteCharacteristicBAR-&gt;readFloat();\r\n  ALTValue = pRemoteCharacteristicALT-&gt;readFloat();\r\n  ECOValue = pRemoteCharacteristicECO-&gt;readFloat();\r\n  VOCValue = pRemoteCharacteristicVOC-&gt;readFloat();\r\n  \r\n}\r\n\/\/ Notify Callback\r\nstatic void notifyCallback(\r\n  BLERemoteCharacteristic* pBLERemoteCharacteristic,\r\n  uint8_t* pData,\r\n  size_t length,\r\n  bool isNotify) {\r\n    Serial.print(&quot;Notify callback for characteristic &quot;);\r\n    Serial.print(pBLERemoteCharacteristic-&gt;getUUID().toString().c_str());\r\n    Serial.print(&quot; of data length &quot;);\r\n    Serial.println(length);\r\n    Serial.print(&quot;data: &quot;);\r\n    Serial.println((char*)pData);\r\n}\r\n\/\/ My Client Callback\r\nclass MyClientCallback : public BLEClientCallbacks {\r\n  void onConnect(BLEClient* pclient) {\r\n  }\r\n\r\n  void onDisconnect(BLEClient* pclient) {\r\n    connected = false;\r\n    Serial.println(&quot;onDisconnect&quot;);\r\n  }\r\n};\r\n\/\/ Connect To Server\r\nbool connectToServer() {\r\n    Serial.print(&quot;Forming a connection to &quot;);\r\n    Serial.println(myDevice-&gt;getAddress().toString().c_str());\r\n\r\n    BLEClient*  pClient  = BLEDevice::createClient();\r\n    Serial.println(&quot; - Created client&quot;);\r\n\r\n    pClient-&gt;setClientCallbacks(new MyClientCallback());\r\n\r\n    \/\/ Connect to the remove BLE Server.\r\n    \/\/ if you pass BLEAdvertisedDevice instead of address,\r\n    \/\/it will be recognized type of peer device address (public or private)\r\n    pClient-&gt;connect(myDevice);  \r\n    Serial.println(&quot; - Connected to server&quot;);\r\n    \/\/set client to request maximum MTU from server (default is 23 otherwise)\r\n    pClient-&gt;setMTU(517); \r\n\r\n    \/\/ Obtain a reference to the service we are after in the remote BLE server.\r\n    BLERemoteService* pRemoteService = pClient-&gt;getService(serviceUUID);\r\n    if (pRemoteService == nullptr) {\r\n      Serial.print(&quot;Failed to find our service UUID: &quot;);\r\n      Serial.println(serviceUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n    Serial.println(&quot; - Found our service&quot;);\r\n\r\n    \/\/ Obtain a reference to the characteristic in the service of the remote BLE server.\r\n    pRemoteCharacteristic = pRemoteService-&gt;getCharacteristic(charUUID);\r\n    if (pRemoteCharacteristic == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID: &quot;);\r\n      Serial.println(charUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n    Serial.println(&quot; - Found our characteristic&quot;);\r\n    \/\/ Temperature Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicTEM = pRemoteService-&gt;getCharacteristic(charTEMUUID);\r\n    if (pRemoteCharacteristicTEM == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID Temperature: &quot;);\r\n      Serial.println(charTEMUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n    \/\/ Humidity Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicHUM = pRemoteService-&gt;getCharacteristic(charHUMUUID);\r\n    if (pRemoteCharacteristicHUM == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID Temperature: &quot;);\r\n      Serial.println(charHUMUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n\r\n    Serial.println(&quot; - Found our characteristic&quot;);\r\n\r\n    \/\/ Barometric Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicBAR = pRemoteService-&gt;getCharacteristic(charBARUUID);\r\n    if (pRemoteCharacteristicBAR == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID Barometric: &quot;);\r\n      Serial.println(charBARUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n\r\n    Serial.println(&quot; - Found our characteristic&quot;);\r\n    \r\n    \/\/ Altitude Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicALT = pRemoteService-&gt;getCharacteristic(charALTUUID);\r\n    if (pRemoteCharacteristicALT == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID Altitude: &quot;);\r\n      Serial.println(charALTUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n\r\n    \/\/ eCO2 Concentration Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicECO = pRemoteService-&gt;getCharacteristic(charECOUUID);\r\n    if (pRemoteCharacteristicECO == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID eCO2 Concentration: &quot;);\r\n      Serial.println(charECOUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n\r\n    Serial.println(&quot; - Found our characteristic&quot;);\r\n    \r\n    \/\/ tVOC Concentration Obtain a reference to the characteristic in the service\r\n    \/\/ of the remote BLE server.\r\n    pRemoteCharacteristicVOC = pRemoteService-&gt;getCharacteristic(charVOCUUID);\r\n    if (pRemoteCharacteristicVOC == nullptr) {\r\n      Serial.print(&quot;Failed to find our characteristic UUID tVOC Concentration: &quot;);\r\n      Serial.println(charVOCUUID.toString().c_str());\r\n      pClient-&gt;disconnect();\r\n      return false;\r\n    }\r\n    \r\n    \r\n    Serial.println(&quot; - Found our characteristic&quot;);\r\n    \/\/ Read the value of the characteristic.\r\n    if(pRemoteCharacteristic-&gt;canRead()) {\r\n      std::string value = pRemoteCharacteristic-&gt;readValue();\r\n      Serial.print(&quot;The characteristic value was: &quot;);\r\n      Serial.println(value.c_str());\r\n    }\r\n\r\n    if(pRemoteCharacteristic-&gt;canNotify())\r\n      pRemoteCharacteristic-&gt;registerForNotify(notifyCallback);\r\n\r\n    connected = true;\r\n    return true;\r\n    \r\n}\r\n\/**\r\n * Scan for BLE servers and find the first one that advertises the service we are looking for.\r\n *\/\r\nclass MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {\r\n \/**\r\n   * Called for each advertising BLE server.\r\n   *\/\r\n  void onResult(BLEAdvertisedDevice advertisedDevice) {\r\n    Serial.print(&quot;BLE Advertised Device found: &quot;);\r\n    Serial.println(advertisedDevice.toString().c_str());\r\n\r\n    \/\/ We have found a device, let us now see if it contains the service we are looking for.\r\n    if (advertisedDevice.haveServiceUUID() &amp;&amp; advertisedDevice.isAdvertisingService(serviceUUID)) {\r\n\r\n      BLEDevice::getScan()-&gt;stop();\r\n      myDevice = new BLEAdvertisedDevice(advertisedDevice);\r\n      doConnect = true;\r\n      doScan = true;\r\n\r\n    } \/\/ Found our server\r\n  } \/\/ onResult\r\n}; \/\/ MyAdvertisedDeviceCallbacks\r\n<\/pre>\n<p><strong>getDisplay.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Display\r\n\/\/ SHARP Memory Display - UID\r\nvoid isDisplayUID() {\r\n\r\n    \/\/ Text Display \r\n    \/\/ Clear Display\r\n    display.clearDisplay();\r\n    display.setRotation(2);\r\n    display.setTextSize(3);\r\n    display.setTextColor(BLACK);\r\n    \/\/ Don Luc Electronics\r\n    display.setCursor(0,10);\r\n    display.println( &quot;Don Luc&quot; );\r\n    display.setTextSize(2);\r\n    display.setCursor(0,40);\r\n    display.println( &quot;Electronics&quot; );\r\n    \/\/ Version\r\n    display.setTextSize(3);\r\n    display.setCursor(0,70);\r\n    display.println( &quot;Version&quot; );\r\n    display.setTextSize(2);\r\n    display.setCursor(0,100);   \r\n    display.println( sver );\r\n    \/\/ Refresh\r\n    display.refresh();\r\n    delay( 5000 );\r\n    \r\n}\r\n\/\/ Display Environmental\r\nvoid isDisplayEnvironmental(){\r\n\r\n    \/\/ Text Display Environmental\r\n    \/\/ Clear Display\r\n    display.clearDisplay();\r\n    display.setRotation(2);\r\n    display.setTextSize(2);\r\n    display.setTextColor(BLACK);\r\n    \/\/ Temperature Celsius\r\n    display.setCursor(0,5);\r\n    display.print( &quot;T: &quot; );\r\n    display.print( TEMValue );    \r\n    display.println( &quot;C&quot; );\r\n    \/\/ Humidity\r\n    display.setCursor(0,25);\r\n    display.print( &quot;H: &quot; );\r\n    display.print( HUMValue );\r\n    display.println( &quot;%&quot; );\r\n    \/\/ Pressure\r\n    display.setCursor(0,45);\r\n    display.print( &quot;B: &quot; );\r\n    display.print( BARValue );\r\n    display.println( &quot;&quot; );\r\n    \/\/ Altitude Meters\r\n    display.setCursor(0,65);\r\n    display.print( &quot;A: &quot; );   \r\n    display.print( ALTValue );\r\n    display.println( &quot;M&quot; );\r\n    \/\/ eCO2 Concentration\r\n    display.setCursor(0,85);\r\n    display.print( &quot;C: &quot; );\r\n    display.print( ECOValue );\r\n    display.println( &quot;ppm&quot; );\r\n    \/\/ tVOC Concentration\r\n    display.setCursor(0,105);\r\n    display.print( &quot;V: &quot; );\r\n    display.print( VOCValue );\r\n    display.println( &quot;ppb&quot; );\r\n    \/\/ Refresh\r\n    display.refresh();\r\n    delay( 100 );\r\n\r\n}\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Setup\r\nvoid setup()\r\n{\r\n  \r\n  \/\/ Serial\r\n  Serial.begin(115200);\r\n  Serial.println(&quot;Starting Arduino BLE Client application...&quot;);\r\n\r\n  \/\/ Initialize digital pin iLED as an output\r\n  pinMode(iLED, OUTPUT);\r\n  \/\/ Turn the LED on HIGH\r\n  digitalWrite(iLED, HIGH);\r\n\r\n  \/\/ SHARP Display start &amp; clear the display\r\n  display.begin();\r\n  display.clearDisplay();\r\n\r\n  \/\/ Display UID\r\n  isDisplayUID();\r\n\r\n  \/\/ Bluetooth BLE\r\n  BLEDevice::init(&quot;&quot;);\r\n  \r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n  \r\n  BLEScan* pBLEScan = BLEDevice::getScan();\r\n  pBLEScan-&gt;setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());\r\n  pBLEScan-&gt;setInterval(1349);\r\n  pBLEScan-&gt;setWindow(449);\r\n  pBLEScan-&gt;setActiveScan(true);\r\n  pBLEScan-&gt;start(5, false);\r\n\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>People can contact us:<\/strong> https:\/\/www.donluc.com\/?page_id=1927<\/p>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>IoT<\/li>\n<li>Wireless (Radio Frequency, Bluetooth, WiFi, Etc&#8230;)<\/li>\n<li>Robotics<\/li>\n<li>Camera and Video Capture Receiver Stationary, Wheel\/Tank and Underwater Vehicle<\/li>\n<li>Unmanned Vehicles Terrestrial and Marine<\/li>\n<li>Machine Learning<\/li>\n<li>RTOS<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<\/ul>\n<p><strong>Instructor, E-Mentor, STEAM, and Arts-Based Training<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>IoT<\/li>\n<li>PIC Microcontrollers<\/li>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>Luc Paquin \u2013 Curriculum Vitae &#8211; 2023<\/strong><br \/>\nhttps:\/\/www.donluc.com\/luc\/<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/@thesass2063<br \/>\n<strong>Twitter:<\/strong> https:\/\/twitter.com\/labs_steam<br \/>\n<strong>Pinterest:<\/strong> https:\/\/www.pinterest.com\/NeoSteamLabs\/<br \/>\n<strong>Instagram:<\/strong> https:\/\/www.instagram.com\/neosteamlabs\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; #DonLucElectronics #DonLuc #RadioFrequency #Bluetooth #Display #SparkFun #BME280 #CCS811 #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212;- Bluetooth Server and Client Connect the SparkFun BME280 and CCS811 this is the &#8220;Server&#8221; board. Upload SparkFun Thing Plus the Server code to the board using the USB cable. When uploading is complete, disconnect this &#8230; <a title=\"Project #26 &#8211; Radio Frequency &#8211; Bluetooth Server and Client &#8211; Mk26\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=3581\" aria-label=\"Read more about Project #26 &#8211; Radio Frequency &#8211; Bluetooth Server and Client &#8211; Mk26\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,49,38,80,59,115,5,287,79,10,43],"tags":[6,92,242,299,102,4,87,19,83,85,24,9,84,27,264,109,33,34,108],"class_list":["post-3581","post","type-post","status-publish","format-standard","hentry","category-radio-frequency","category-consultant","category-digitalelectronics","category-esp32","category-fritzing","category-e-mentor","category-microcontrollers","category-program","category-program_esp8266","category-projects","category-sparkfun","tag-arduino","tag-battery","tag-bluetooth","tag-bluetooth-server-and-client","tag-components","tag-consultant","tag-display","tag-electronics","tag-esp32","tag-fritzing","tag-microcontroller","tag-programming","tag-programming-esp32","tag-projects-2","tag-radio-frequency","tag-sparkfun","tag-technology","tag-video-blog","tag-vlog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3581"}],"version-history":[{"count":2,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3581\/revisions"}],"predecessor-version":[{"id":4624,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3581\/revisions\/4624"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}