技术标签: Arduino ESP32 零基础入门实例教程 esp32蓝牙
BLEAssist
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLECharacteristic *pCharacteristic;
bool deviceConnected = false;
char BLEbuf[32] = {
0};
uint32_t cnt = 0;
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) {
Serial.print("------>Received Value: ");
for (int i = 0; i < rxValue.length(); i++) {
Serial.print(rxValue[i]);
}
Serial.println();
if (rxValue.find("A") != -1) {
Serial.print("Rx A!");
}
else if (rxValue.find("B") != -1) {
Serial.print("Rx B!");
}
Serial.println();
}
}
};
void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("ESP32 BLE Test");
// 创建蓝牙服务器
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
// // 创建广播服务的UUID
BLEService *pService = pServer->createService(SERVICE_UUID);
创建广播服务的UUID
pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
pCharacteristic->addDescriptor(new BLE2902());
BLECharacteristic *pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE);
pCharacteristic->setCallbacks(new MyCallbacks());
// 开始蓝牙服务
pService->start();
// 开始广播
pServer->getAdvertising()->start();
Serial.println("Waiting a client connection to notify...");
}
void loop() {
if (deviceConnected) {
//设备连接后,每秒钟发送txValue。
memset(BLEbuf, 0, 32);
memcpy(BLEbuf, (char*)"Hello BLE APP!", 32);
pCharacteristic->setValue(BLEbuf);
pCharacteristic->notify(); // Send the value to the app!
Serial.print("*** Sent Value: ");
Serial.print(BLEbuf);
Serial.println(" ***");
}
delay(1000);
}
connect
进行连接AuthenticationEntryPoint简介AuthenticationEntryPoint是Spring Security Web一个概念模型接口,顾名思义,他所建模的概念是:“认证入口点”。它在用户请求处理过程中遇到认证异常时,被ExceptionTranslationFilter用于开启特定认证方案(authentication schema)的认证流程。该接口只定义了一个方法 :void commence(HttpServletRequest request, HttpServlet
excel的表头(第一行)不能是中文,也不能没有表头,否则都会报这个错,解决方法是把表头字段名用英文描述。
java 泛型(generics)是 JDK 5 中引入的一个新特性, 泛型提供了编译时类型安全检测机制,该机制允许程序员在编译时检测到非法的类型。泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数。假定我们有这样一个需求:写一个排序方法,能够对整型数组、字符串数组甚至其他任何类型的数组进行排序,该如何实现?答案是可以使用 Java 泛型。使用 Java 泛型的概念,我们可...
由于数据集大端小端的问题,Python的二进制文件读取可能出现误读,因此需要利用struct类中方法,进行大端小端转化。对于MNIST数据集的读取参见:http://www.cnblogs.com/x1957/archive/2012/06/02/2531503.htmlGIST 数据集为例:(小端)import osimport structfrom os.path
线程基础import threading #线程库import timeimport queueclass myThread(threading.Thread): #继承线程库里面的Thread类 def __init__(self,threadname,threadid,waittime): '''线程名,线程id,等待执行时间''' threading.Thread.__init__(self) #必须要有这句 没有的话就报错 se
#include #include #include using namespace std;/*问题:实现一个堆排序分析:堆,用数组表示的话:设数组x[1..n],则有根节点为x[1],孩子结点下标为2*i,2*i+1,父节点下标为i/2,大顶堆:任何结点的值>=其父节点的值采用小顶堆排序的步骤:1 步骤1:设置第一个元素为根节点,后续插入的结点放在已有结点后面,采用向上调
网上关于cocos2d-x的安装教程有很多,但是都是旧版本的,我找了很多资料都无法创建proj.android-studio。后来发现是新版本的软件对安卓平台进行合并,只有proj.android文件,使用Android studio编写。一、安装准备:JDK –->> Java SE Development Kit 8u202 Android studio -->...
在大数据学习过程中会遇到各种各样得错误,儿我们就需要解决这些错误,所以我就遇到一个错误,并记录解决得方法。错误:FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient。解决方法:1、查看
一、submit提交在form标签中添加action(提交的地址)和method(post),且有一个submit按钮()就可以进行数据的提交,每一个input标签都需要有一个name属性,才能进行提交。当点击登录时,提交的数据是:username=username&password=password这种默认的提交方式,一般会进行页面的跳转(不成功时跳转到当前页面),而有时我们是对弹出框进...
etcd 核心模块下图中展示了 etcd 如何处理一个客户端请求涉及到的模块和流程。图中淡紫色的矩阵表示 etcd ,它包括如下几个模块:etcd server:对外接受客户端的请求,请求 etcd 代码中的 etcd server 目录,其中还有一个 raft.go 的模块与 etcd raft 库进行通信。etcd server 中与存储相关的模块是 applierV3,这里封装了 V3 版本的数据存储, WAL(write ahead log),用于写数据日志,etcd 启动时会根据这部分内容进行
瞎扯 2014年毕业的,到现在出来工作一年半左右。在大学学的专业是网络工程,大三下学期跟着老师做了四五个月的web开发,后来自学了Android,选择它是因为自己的一个兴趣,所以后来工作顺理成章的找了Android开发的工作。到今年六月初的时候,第一次换了工作,来到新公司后,第一次接触到了项目持续集成的概念,并且在来到新公司开始的一两个月,老大让我去了解学习了下,这里我整理了下我所知道的关于Jen
交叉编译环境(执行uname –a后):Host:Linux localhost.localdomain 2.6.18-8.el5xen #1 SMP Fri Jan 26 14:42:21 EST 2007 i686 athlon i386 GNU/LinuxTargets:Linux uclibc 2.6.15-sigma #11 PREEMPT Fri Feb 13 15