esp8266 / esp8266/Arduino

esp8266 smartconfig V2.5.4 Unable to connect to the distribution network with esptouch app

Open
#9,317 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

`
#include
#include

// 回调函数
void smartConfigCallback(uint32_t st, void* result)
{
sc_status status = (sc_status) st;
Serial.printf("[SmartConfig] status:%d\n", status);

if (status == SC_STATUS_FIND_CHANNEL) {
Serial.println("正在扫描信道... 请打开 ESP-Touch App 开始配网");
}
else if (status == SC_STATUS_GETTING_SSID_PSWD) {
Serial.println("正在接收 SSID 和密码...");
if (result != NULL) {
sc_type *type = (sc_type*)result;
if (*type == SC_TYPE_ESPTOUCH) {
Serial.println("协议类型: ESP-Touch");
} else if (*type == SC_TYPE_AIRKISS) {
Serial.println("协议类型: AirKiss");
}
}
}
else if (status == SC_STATUS_LINK) {
Serial.println("已成功获取 SSID 和密码!正在连接路由器...");

if (result != NULL) {
struct station_config *sta_conf = (struct station_config *)result;

// 保存配置并连接
wifi_station_set_config(sta_conf);
wifi_station_disconnect();
wifi_station_connect();
}
}
else if (status == SC_STATUS_LINK_OVER) {
Serial.println("SmartConfig 配网成功!已连接到路由器");

if (result != NULL) {
uint8_t *ip = (uint8_t*)result;
Serial.printf("手机端 IP: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
}

smartconfig_stop(); // 停止 SmartConfig,释放资源
Serial.print("设备本地 IP: ");
Serial.println(WiFi.localIP());
}
else {
Serial.printf("未知状态: %d\n", status);
}
}

void setup() {
Serial.begin(115200);
delay(1000);
// We start by connecting to a WiFi network
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);

Serial.println(smartconfig_get_version());

esptouch_set_timeout(30);

if(smartconfig_start(reinterpret_cast(smartConfigCallback), 1))
{
Serial.println("SmartConfig 已启动,等待手机发送配置...");
} else {
Serial.println("SmartConfig 启动失败!");
return;
}
}

void loop() {

delay(5000);
}`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.