标签: esp32

将示例代码重构为类不会引发重载函数的实例

我是 CPP 的新手,并尝试将此示例代码https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WPS/WPS.ino “重构”为名为ApiClient`的类。然后我希望能够做这样的事情:

apiClient = ApiClient(myUrl);
apiClient.sendValue(key, value);
Run Code Online (Sandbox Code Playgroud)

除了函数调用之外,所有内容都会编译wifi.onEvent(WiFiEvent);。当我将整个示例代码复制粘贴到我的main.cpp文件中时,该示例正在运行。当我使用“重构”方法时,他们wifi.onEvent(WifiEvent)会抱怨。

确切的错误信息:

no instance of overloaded function "WiFiClass::onEvent" matches the argument list -- argument types are: (void (system_event_id_t event, system_event_info_t info)) -- object type is: WiFiClass

我知道该onEvent函数通常需要两个参数,但为什么这在示例代码中有效?我该如何解决这个问题?

这是我到目前为止所拥有的:

主程序



#include "WiFi.h"
#include <esp_wps.h>
#include <Hythe22.h>
#include <ApiClient.h>

#define DHTPIN 14
// ?accessKey=ist_NJu3tjPIBCYeJd6DGGBxzq14LvungHoK&bucketKey=B37GHBNK5HL3
#define API_URL "https://groker.init.st/api/events";

Hythe22 dht(DHTPIN);
ApiClient apiClient;
uint64_t chipid;
#define ESP_DEVICE_NAME String(chipid)


void setup()
{
  String apiUrl = "https://myApi.Endpoint.com/event";
  Serial.begin(115200); …
Run Code Online (Sandbox Code Playgroud)

c++ arduino esp32

3
推荐指数
1
解决办法
1393
查看次数

用于 esp32 的 arduino 中的不同 WiFi 模式

我最近开始玩 esp32。我正在寻找适用于 esp32 的各种 WiFi.mode() 选项,但在任何地方都找不到。谁能帮忙指出该信息的来源?

谢谢

esp32

3
推荐指数
1
解决办法
3792
查看次数

如何正确设置 ESP32 上 TCP/IP 适配器的主机名

问题

Espressif 的 ESP-32(在本例中特别是 ESP-WROOM-32)出现在默认主机名“Espressif”的网络上。我不想使用这个主机名,所以我选择如下更改它:

    // Initialize the TCP/IP adapter (launches handler task)
    tcpip_adapter_init();

    // Set the hostname for the default TCP/IP station interface
    if ((err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, g_hostname))
            != ESP_OK) {
        return err;
    }

Run Code Online (Sandbox Code Playgroud)

当然,这行不通。我得到以下错误:ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY.


尝试的解决方案

为了解决这个问题,我会查看 TCP/IP 适配器在完成初始化时是否会发布某种事件。这样我就可以注册一个处理程序来设置主机名。此处的乐鑫 WiFi 驱动程序指南表明任务已启动 - 所以可能有一个事件:

“主任务调用 tcpip_adapter_init() 创建LwIP 核心任务并初始化 LwIP 相关工作。”

好吧,我找不到任何此类事件。无论是API文档,也不是实际的文件本身(tcpip_adapter.h)有它。我检查了事件的头文件,似乎没有任何事件仅用于指示 TCP/IP 适配器已完成启动

/** IP event declarations */
typedef enum {
    IP_EVENT_STA_GOT_IP,               /*!< ESP32 station got …
Run Code Online (Sandbox Code Playgroud)

c embedded tcp driver esp32

3
推荐指数
1
解决办法
5610
查看次数

Arudino / ESP32 模块代码的环境变量

我的 ESP32 模块上有一些简单的 FastLed 和 wifi 代码,但我不想将我的 WIFI ssid 和密码存储在代码中(在 github 上)。因此,我希望将该信息放在一个单独的文件中,该文件不会被签入源代码管理,但会在上传过程中进行编译并加载到 ESP32 上。这可能吗?

我想象我会有一个wifi.env.json文件或在编译时读取的文件,变量在代码中的正确位置使用,然后将带有这些变量的编译代码上传到 ESP32。

我是一名网络开发人员,这是该社区的常见做法,只是好奇是否也可以用于 arudino/ESP32 代码。

c++ arduino environment-variables esp32 fastled

3
推荐指数
1
解决办法
2076
查看次数

逐行读取文件并存入字符串,Flash数据保存SPIFFS

我正在开发一个使用 Flash 数据保存的项目。我正在使用 ESP32 的 SPIFFS 库,目前正在尝试将每行的数据存储到字符串中。由于我可以控制文件中可以包含多少内容,因此不需要超过 3 个字符串来存储数据。我可以轻松地使用 来存储第一行内容readStringUntil。但我无法从第 2 行和第 3 行获取内容。

\n对于第一行,我使用以下代码:

\n
//Pegar a primeira linha do arquivo, onde ser\xc3\xa1 armazenado o nome do WIFI (ssid)\nvoid first_line (){\n  file = SPIFFS.open("/wifi.txt", "r");\n\n  while (file.available()) {\n    String first_line = file.readStringUntil('\\n');\n    Serial.print(first_line);\n    break;\n  }\n\n  file.close();\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我使用此函数将代码写入文件:

\n
// Escrever mensagem dentro do arquivo\nvoid write_file_info(String message) {\n  file = SPIFFS.open("/wifi.txt", FILE_WRITE);\n\n  if (!file){\n    Serial.println("Error opening file");\n    return;\n  }else{\n    Serial.println("Success opening file");\n  }\n\n  if (file.println(message)){\n    Serial.println("File was …
Run Code Online (Sandbox Code Playgroud)

c++ arduino arduino-c++ esp32

3
推荐指数
1
解决办法
1万
查看次数

ESP-IDF 框架中的链接器错误(未定义参考)

我正在学习在 ESP32 平台上编写应用程序。当我尝试编译代码时,我从链接器收到此错误:

对“Serial_Init”的未定义引用

其中Serial_Init是在serial_cli.h文件中声明的函数,该文件位于同一目录和工作空间中。而且,我在那里声明了一些宏,并且可以在我的代码中使用它们没有问题,所以我真的不明白错误来自哪里。这是serial_cli.h

#ifndef _SERIAL__H_
#define _SERIAL__H_

#include "driver/uart.h"

#define SERIAL_PORT         UART_NUM_1
#define RTS_SIG_PINOUT      UART_PIN_NO_CHANGE
#define CTS_SIG_PINOUT      UART_PIN_NO_CHANGE

/**
* @brief This function initialises serial communication with PC
* @param uart_config_t type pointer to structure containing needed parameters
* @param int size of RX and TX buffer (in bytes)
* @param QueueHandle_t type pointer to structure containing UART queue
*/
void Serial_Init(uart_config_t*, const int, QueueHandle_t*);


#endif /* _SERIAL_H_ */
Run Code Online (Sandbox Code Playgroud)

这是serial_cli.c

#include "serial_cli.h"

void …
Run Code Online (Sandbox Code Playgroud)

c esp32 esp-idf

3
推荐指数
1
解决办法
9690
查看次数

Android + ESP32 通过蓝牙 (BLE) 发送数据

我正在尝试通过蓝牙(BLE)将数据从我的 Android 应用程序发送到 esp32,但我找不到正确的方法。我现在能做的就是扫描并找到 BLE 设备。我的 arduino 代码正在按我想要的方式工作(它正确接收数据),因为我使用了另一个应用程序,它可以让我将数据发送到 ble 设备,所以我知道 arduino 代码很好。

\n

我已经在这里搜索了几天并谷歌如何实现它,但我仍然坚持下去。这是我现在的代码:

\n

扫描器:

\n
class BluetoothFragment : Fragment() {\n    private lateinit var binding: FragmentBluetoothBinding\n    private var list : MutableList<BluetoothDevice> = ArrayList()\n    private lateinit var  bluetoothAdapter : BluetoothAdapter\n\n    override fun onCreateView(\n        inflater: LayoutInflater, container: ViewGroup?,\n        savedInstanceState: Bundle?\n    ): View? {\n        // Inflate the layout for this fragment\n        Log.d("DeviceListActivity", "onCreate()")\n        return inflater.inflate(R.layout.fragment_bluetooth, container, false)\n    }\n\n    // TODO: 19/05/2021 implementar listener en el recycler view para crear la conexi\xc3\xb3n con …
Run Code Online (Sandbox Code Playgroud)

android bluetooth arduino bluetooth-lowenergy esp32

3
推荐指数
1
解决办法
7107
查看次数

ESP32 httpd:标头字段太长,服务器无法解释

我想流式传输到 Anrdoid 应用程序内的 WebView。

我的代码是:

WebView cam = (WebView) findViewById(R.id.Cam);
        cam.getSettings().setLoadWithOverviewMode(true);
        cam.getSettings().setUseWideViewPort(true);
        cam.getSettings().setBuiltInZoomControls(true);
        cam.getSettings().setPluginState(WebSettings.PluginState.ON);
        cam.getSettings().setPluginState(WebSettings.PluginState.ON);
        cam.loadUrl("http://192.168.0.10");
Run Code Online (Sandbox Code Playgroud)

它可以在模拟器中运行,但如果我在智能手机上安装该应用程序,它就无法运行。我收到一个错误

Header fields are too long for the server to interpret
Run Code Online (Sandbox Code Playgroud)

如何摆脱这个错误?

android-webview esp32 arduino-esp32

3
推荐指数
1
解决办法
6328
查看次数

CMakeLists - 如何包含源文件和头文件的目录?

我觉得这个问题已经被问过很多次了,但我找到的答案似乎都不适合我。我对 CMake 和 C/C++ 非常陌生,因为我来自 Java 世界,并且正在努力理解 cmake 及其工作原理。

无论如何,基本上我有下面的文件夹结构。这是一个 esp-idf 项目,所以我不知道这是否与我遇到的问题有关。

main
-CMakeLists.txt
-main.cpp
-wifi.cpp
Metriful
-CMakeLists.txt
-Metriful_sensor.cpp
-Metriful_sensor.h
-Wifi_functions.h
-Wifi_functions.cpp
CMakeLists.txt
Makefile
Run Code Online (Sandbox Code Playgroud)

现在,我想做的就是包含 Metriful 子目录,这样我就可以使用“库”提供的功能。现在根目录中的 CMakeLists.txt 如下所示:

cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ESP_32_WROOM32_SENSOR_-_Metriful)

include_directories("Metriful")
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用,因为在我的 main.cpp 中包含“Metriful_sensor.h”仍然失败:

cmake -G Ninja .. <

-- ccache will be used for faster recompilation
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file C:/Users/User/PlatformIO/ESP32_WROOM32_Sensor_-_Metriful/sdkconfig
-- Could NOT find Perl (missing: PERL_EXECUTABLE) 
CMake Warning (dev) at C:/Users/User/esp/esp-idf/components/mbedtls/CMakeLists.txt:114 (target_sources):
  Policy CMP0076 is not set: …
Run Code Online (Sandbox Code Playgroud)

c++ cmake esp32 esp-idf

3
推荐指数
1
解决办法
9291
查看次数

如何抑制 esp-idf 和 cmake 中的开关警告

我有一个最初是为 Particle 设备编写的项目,我们正在从他们的设备转向 ESP32。我一直致力于将我们的一个设备的代码移植到 esp-idf,现在收到大量与 switch 语句相关的警告,其中没有默认值,因此无法编译。由于某种原因,无论粒子设备使用什么编译器,都不关心这个问题。虽然我当然可以检查并更正代码,但现在不是这样做的时间或地点,我需要抑制这些警告。最终我们将纠正原始代码并推送到这个分支。

../main/Services/ConfigurationParser.cpp:295:16: error: enumeration value 'psAmbientTemperature' not handled in switch [-Werror=switch]
Run Code Online (Sandbox Code Playgroud)

我不太了解这个平台或编译器,不知道如何在以后抑制它们,并且无法在其他地方找到信息。任何帮助是极大的赞赏。

c++ cmake esp32 esp-idf

3
推荐指数
1
解决办法
2911
查看次数