/*-------------------------------------------------------------- Description: This is Arduino code for Bluetooth device to read temperature values from Thermocouple and translates them over BLE (Bluetooth Low Energy) Application: Manufactured device connected to the Roasters Pal app enables to record temperatures automatically. Hardware: ESP32 board, MAX6675 (Thermocouple). Software: Developed using Arduino 2.0.2 software Libraries: MAX6675 - https://github.com/YuriiSalimov/MAX6675_Thermocouple Bluetooth Low Energy - https://github.com/espressif/arduino-esp32/tree/master/libraries/BLE Date: 25 Apr 2023 Author: © RoastersPal.com Licence: MIT License Copyright (c) 2023 RoastersPal.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.. ------------------------------------------------------------------------------------------------------*/ //Include libraries #include #include #include #include #include #include #include //define properties and values BLECharacteristic *characteristicTX; BLECharacteristic *characteristicTX_1; bool deviceConnected = false; #define SERVICE_UUID "1fc7e3ac-e544-4c01-adc4-94d13757e086" #define CHARACTERISTIC_UUID_TX "00001001-0000-1000-8000-00805F9B34FB" #define CHARACTERISTIC_UUID_TX_1 "00001002-0000-1000-8000-00805F9B34FB" #define ET_SCK 12 #define ET_CS 14 #define ET_SO 27 #define SMOOTHING_FACTOR 5 //define Thermocouple Thermocouple* thermocouple = NULL; double temp_BT_C; double temp_BT_F; bool tempInFarenheits = false; //define BLE Server class ServerCallbacks: public BLEServerCallbacks { void onConnect(BLEServer* pServer) { deviceConnected = true; Serial.println("RPal BT connected..."); }; void onDisconnect(BLEServer* pServer) { deviceConnected = false; Serial.println("Device not connected..."); BLEDevice::startAdvertising(); } }; //initialize device void setup() { Serial.begin(115200); // Initiate thermocouple: Thermocouple* originThermocouple = new MAX6675_Thermocouple(ET_SCK, ET_CS, ET_SO); thermocouple = new SmoothThermocouple(originThermocouple, SMOOTHING_FACTOR); // Create the BLE Device BLEDevice::init("RPal BT x1T"); // Do not change! Device in Roaster Pal recognized by name // Create the BLE Server BLEServer *server = BLEDevice::createServer(); server->setCallbacks(new ServerCallbacks()); BLEService *service = server->createService(SERVICE_UUID); // Create the BLE Service characteristicTX = service->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);// Create a BLE NOTIFY Characteristic (TX pin) characteristicTX->addDescriptor(new BLE2902());//add descriptor to NOTIFY charecteristic characteristicTX->setBroadcastProperty(true); characteristicTX_1 = service->createCharacteristic(CHARACTERISTIC_UUID_TX_1, BLECharacteristic::PROPERTY_NOTIFY);// Create a BLE NOTIFY Characteristic (TX_1 pin) characteristicTX_1->addDescriptor(new BLE2902()); //add descriptor to NOTIFY charecteristic TX_1 characteristicTX_1->setBroadcastProperty(true); service->start();// Start the service BLEDevice::startAdvertising(); Serial.println("Waiting for devices to be connected..."); } //read temperatures from device void displayTemperatures() { delay(1000); // Delay for 1 seconds // Reads temperature from thermocouple const double BT_C = thermocouple->readCelsius(); const double BT_F = thermocouple->readFahrenheit(); temp_BT_C=BT_C; temp_BT_F=BT_F; if (deviceConnected) { char txString[8]; dtostrf(temp_BT_C, 2, 2, txString); // float_val, min_width, digits_after_decimal, char_buffer characteristicTX->setValue(txString); Serial.print("BT_C..."); Serial.println(txString); characteristicTX->notify(); char txString1[8]; dtostrf(temp_BT_F, 2, 2, txString1); characteristicTX_1->setValue(txString1); Serial.print("BT_F..."); Serial.println(txString1); characteristicTX_1->notify(); // Envia o valor para o smartphone } } //loop readings void loop() { displayTemperatures(); }