最近想做一个发热垫,能够用手机管制。

一开始思考过用wifi接入米家进行管制,这样还能应用语音助手。但起初认真考虑一番,发现应用场景不对。如果应用wifi连贯,那意味着只能在室内应用了。

所以,最初还是决定间接应用蓝牙连贯。

硬件选型

尽管抉择了蓝牙连贯,但为了当前扩大wifi不便,所以硬件选用了esp32,同时有wifi和蓝牙连贯的性能,代码又兼容arduino,应用十分不便。

蓝牙连贯形式

  1. 初步构想是把硬件的mac地址生成二维码,手机软件扫描二维码获取mac地址,进行连贯及发送温度设置等指令。
  2. 起初发现,貌似能够间接用设施名进行蓝牙连贯,如此一来便能够把所有的硬件设施都设置为雷同的设施名,又能够省去二维码,着实不错。
  3. 最初是在查资料时看到一种蓝牙播送的形式,不过尚未来及做试验,日后有机会倒能够试试。

温控形式

应用温敏电阻即可读取温度。

  1. 最简略的温控能够是间接用继电器开关进行管制。设置温度的高低区间,加热到上区间进行,低于下区间则重启加热。
  2. 高阶一点的是用pwm的形式调整发热电阻的功率,离指标温度越靠近则功率越小,如此即可实现平滑温度曲线。甚至于再不行,还可上pid闭环控制算法,叠加上之前的误差,实时调整。

手机软件

因为我不会做安卓软件,当初只是应用一款“蓝牙串口”的app间接发送指令,管制硬件。

当前还是要学一下安卓,做一套架子进去。

esp32程序

//This example code is in the Public Domain (or CC0 licensed, at your option.)//By Evandro Copercini - 2018////This example creates a bridge between Serial and Classical Bluetooth (SPP)//and also demonstrate that SerialBT have the same functionalities of a normal Serial#include "BluetoothSerial.h"#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it#endifBluetoothSerial SerialBT;char START_FLAG = '$';char END_FLAG = '#';int TEMPERATURE_MIN = 0;int TEMPERATURE_MAX = 50;void setup() {  Serial.begin(115200);  SerialBT.begin("ESP32test"); //Bluetooth device name  Serial.println("The device started, now you can pair it with bluetooth!");}void SerialBT_sendMsg(String msg) {  int i = 0;  for (i = 0; i < msg.length(); i++) {    SerialBT.write(msg[i]);  }}int NONE = 0;int START = 1;int pre_status = NONE;int num = 0;void loop() {  if (SerialBT.available()) {    char msg_char = SerialBT.read();    if (msg_char == START_FLAG) {      num = 0;      pre_status = START;    } else if (msg_char == END_FLAG && pre_status == START) {      if (num >= TEMPERATURE_MIN && num <= TEMPERATURE_MAX) {        String msg = String("set temperature to " + String(num) + "\n");        SerialBT_sendMsg(msg);      }      num = 0;      pre_status = NONE;    } else if (isDigit(msg_char) && pre_status == START) {      num = num * 10 + (msg_char - '0');    } else {      num = 0;      pre_status = NONE;    }    // SerialBT_sendMsg(String(String(msg_char) + "\n"));  }        delay(20);}