Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 如何使用ESP32通过BLE发送和接收数据?_Ionic Framework_Bluetooth Lowenergy_Microcontroller_Esp32 - Fatal编程技术网

Ionic framework 如何使用ESP32通过BLE发送和接收数据?

Ionic framework 如何使用ESP32通过BLE发送和接收数据?,ionic-framework,bluetooth-lowenergy,microcontroller,esp32,Ionic Framework,Bluetooth Lowenergy,Microcontroller,Esp32,ESP32需要通过BLE(蓝牙低能耗)与Cross平台应用程序通信。通过BLE发送数据 定义逐字节发送数据的功能和逻辑 void sendSomeDataBLE(uint8\u t*message,int messageSize){ uint8_t txValue=0; while(txValuesetValue(&message[txValue],1); pTxCharacteristic->notify(); txValue++; 延迟(100);//如果发送的数据包太多,蓝牙堆栈将陷入拥塞

ESP32需要通过BLE(蓝牙低能耗)与Cross平台应用程序通信。

通过BLE发送数据
  • 定义逐字节发送数据的功能和逻辑
  • void sendSomeDataBLE(uint8\u t*message,int messageSize){
    uint8_t txValue=0;
    while(txValuesetValue(&message[txValue],1);
    pTxCharacteristic->notify();
    txValue++;
    延迟(100);//如果发送的数据包太多,蓝牙堆栈将陷入拥塞
    }
    }
    
  • 计算消息长度,malloc一个字符数组
  • int messageLength=10;//或者以某种方式测量
    uint8_t*消息=(uint8_t*)malloc(sizeof(uint8_t)*消息长度);
    
  • 将uint8\u t数组的指针传递给函数
  • sendSomeDataBLE(&message[0],messageLength);
    
    通过BLE接收数据
  • 定义将接收的值与字符串进行比较的函数
  • bool compareData(接收到std::string,预定义了std::string){
    int receivedLength=received.length();
    int predefinedLength=预定义的.length();
    如果((接收长度/2)!=预定义长度){
    返回false;
    }
    for(int i=0;i
  • 捕获通过回调函数接收的所有数据
  • class MyCallbacks:public BLECharacteristicCallbacks{
    写入时无效(BLECharacteristic*pCharacteristic){
    std::string rxValue=pCharacteristic->getValue();
    std::string lwnCommand=“lwn”;
    if(比较数据(rxValue,lwnCommand)){
    Serial.println(“接收到lwn命令”);
    }
    }
    }
    

    此外,您确实需要启动BLE并设置RX和TX的字符。

    假设您正在谈论离子。在这种情况下,您可以使用BLE插件,使用protobufs实现传输层,然后添加curce25519加密和SHA256哈希以证明拥有(如果您正在使用它)来创建共享密钥。然后使用AES(CTR模式)加密/解密。最后,您需要创建protobuf_pb.js文件,以插入类似于google-protobuf.js的内容,从而实际生成您的消息

    这并不简单

    可编程插件 首先要做的是启动并运行它:

    import { BLE } from '@ionic-native/ble/ngx'; 
    
    这是个好主意。有很多很好的教程可以让它工作

    原型缓冲区 我推荐谷歌protobuf。使用commonJS导入将.proto文件作为_pb.js导入:

    $ protoc --js_out=import_style=commonjs,binary:. messages.proto base.proto
    
    然后在your.ts文件中,使用类似以下内容:

    var messages = require("../../assets/js/wifi_scan_pb");
    var message = new messages.RespScanStatus();
    
    import { sharedKey, generateKeyPair } from 'curve25519-js';
    
    let keyPairClient = generateKeyPair(seedClient);
    let keyPairDevice = generateKeyPair(seedDevice);
    let shared_key = sharedKey(keyPairClient.private, keyPairDevice.public);
    
    ...  you get the picture... 
    
    作为如何使用扫描结果端点的示例

    密码学 它说它是可选的,但实际上,如果你不使用它,你就是个白痴。所以,不要跳过这一步,因为这很难。您可以使用以下内容:

    var messages = require("../../assets/js/wifi_scan_pb");
    var message = new messages.RespScanStatus();
    
    import { sharedKey, generateKeyPair } from 'curve25519-js';
    
    let keyPairClient = generateKeyPair(seedClient);
    let keyPairDevice = generateKeyPair(seedDevice);
    let shared_key = sharedKey(keyPairClient.private, keyPairDevice.public);
    
    ...  you get the picture... 
    
    然后可能使用crypto js将加密的其余部分拼凑起来。它与AES、SHA256一起出现。别忘了在共享密钥生成中合并占有证明。它提供了值得一提的安全级别

    然后呢 从设备发送和接收内容。这都是些标准的东西。我不是异想天开地说,因为我知道关于BLE的一切,我可以这么说,因为我推荐的库处理得很好,尽管我对BLE一无所知


    很抱歉,这是一个巨大的背后的痛苦,但这是诚实的回答,你需要做什么来发送东西与ESP32使用BLE。

    Heyy我有困难形成整个结构的代码,你能分享完整的代码吗?