android - ESP32 在与 MIT App Inventor 2 交互时停止一切
问题描述
现在制作一个通过经典蓝牙与 ESP32 交互的应用程序。我正在读取霍尔传感器并在其值高于 0 时发送 0,在低于 0 时发送 1。现在,当我在 ai2 中注册该 1 并且因此在应用程序中发生一些事情时,ESP32 发生故障或其他什么。我停止从串行监视器中的传感器获取读数,并且蓝牙连接停止。似乎整个 esp 都停在了原地。我也没有向 ESP32 发送任何数据,只是从中接收数据。esp代码超级小,但app代码不多。解决此问题的唯一方法是重置 esp,这在我的用例中并不可行。有任何解决这个问题的方法吗?
#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
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("Sport Spel"); //Bluetooth device name
}
void loop() {
Serial.println(hallRead());
if (SerialBT.available)
{
if (hallRead() < 0)
{
SerialBT.write('1');
}
else
{
SerialBT.write('0');
}
delay(20);
}
}
解决方案
线
if (SerialBT.available)
应该
if (SerialBT.available())
正如您在问题中所写的那样,您正在测试对象上命名的方法的地址是否available
为SerialBT
真,它总是如此。您想要实际调用该方法,因此您需要包含括号才能调用它。
推荐阅读
- java - Find user's member of groups in Microsoft AD inside Domain Users security group
- php - 将数据表单发送到数据库不起作用
- java - 模块化项目使用 jOpenDocument 上升 InvalidModuleDescriptorException
- java - 如何将图像 url 保存在 firebase 实时数据库中?
- dart - 飞镖:微型
- android - 使用导航组件时在片段之间传递数据有什么限制?
- javascript - 我想从mysql的connection.query中取出结果并将其保存在nodejs的全局范围链中
- node.js - MongoDB 查找和展开没有给出正确的结果
- cassandra - Cassandra 在执行查询时读取超时以进行批量删除
- git - new_git_repository 中 build_file 内容的更改导致再次克隆