-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from harry-boe/feature/SmartConfig
Feature/smart config
- Loading branch information
Showing
6 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
##################################################################### | ||
#### Please don't change this file. Use Makefile-user.mk instead #### | ||
##################################################################### | ||
# Including user Makefile. | ||
# Should be used to set project-specific parameters | ||
include ./Makefile-user.mk | ||
|
||
# Important parameters check. | ||
# We need to make sure SMING_HOME and ESP_HOME variables are set. | ||
# You can use Makefile-user.mk in each project or use enviromental variables to set it globally. | ||
|
||
ifndef SMING_HOME | ||
$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) | ||
endif | ||
ifndef ESP_HOME | ||
$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) | ||
endif | ||
|
||
# Include main Sming Makefile | ||
ifeq ($(RBOOT_ENABLED), 1) | ||
include $(SMING_HOME)/Makefile-rboot.mk | ||
else | ||
include $(SMING_HOME)/Makefile-project.mk | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Local build configuration | ||
## Parameters configured here will override default and ENV values. | ||
## Uncomment and change examples: | ||
|
||
## Add your source directories here separated by space | ||
# MODULES = app | ||
# EXTRA_INCDIR = include | ||
|
||
## ESP_HOME sets the path where ESP tools and SDK are located. | ||
## Windows: | ||
# ESP_HOME = c:/Espressif | ||
|
||
## MacOS / Linux: | ||
# ESP_HOME = /opt/esp-open-sdk | ||
|
||
## SMING_HOME sets the path where Sming framework is located. | ||
## Windows: | ||
# SMING_HOME = c:/tools/sming/Sming | ||
|
||
## MacOS / Linux | ||
# SMING_HOME = /opt/sming/Sming | ||
|
||
## COM port parameter is reqruied to flash firmware correctly. | ||
## Windows: | ||
# COM_PORT = COM3 | ||
|
||
## MacOS / Linux: | ||
# COM_PORT = /dev/tty.usbserial | ||
|
||
## Com port speed | ||
# COM_SPEED = 115200 | ||
|
||
## Configure flash parameters (for ESP12-E and other new boards): | ||
# SPI_MODE = dio | ||
|
||
## SPIFFS options | ||
DISABLE_SPIFFS = 1 | ||
# SPIFF_FILES = files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<b>Introduction</b> | ||
|
||
Espressif’s ESP-TOUCH protocol implements Smart Config technology to help users connect ESP8266EX-embedded devices to a Wi-Fi network through simple configuration on a smartphone. | ||
|
||
Ths sampe here is based on the SDK SmartConfig example code. | ||
|
||
More info including Android and iOS Apsp can be found here: | ||
|
||
http://espressif.com/en/products/software/esp-touch/overview | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <user_config.h> | ||
#include <SmingCore.h> | ||
|
||
|
||
// Will be called when WiFi station was connected to AP | ||
void connectOk() | ||
{ | ||
printf("I'm CONNECTED\n"); | ||
} | ||
|
||
// Will be called when WiFi station timeout was reached | ||
void connectFail() | ||
{ | ||
printf("I'm NOT CONNECTED. Need help :(\n"); | ||
// .. some you code for device configuration .. | ||
} | ||
|
||
void smartconfig_done(sc_status status, void *pdata) | ||
{ | ||
switch(status) { | ||
case SC_STATUS_WAIT: | ||
printf("SC_STATUS_WAIT\n"); | ||
break; | ||
case SC_STATUS_FIND_CHANNEL: | ||
printf("SC_STATUS_FIND_CHANNEL\n"); | ||
break; | ||
case SC_STATUS_GETTING_SSID_PSWD: { | ||
printf("SC_STATUS_GETTING_SSID_PSWD\n"); | ||
sc_type *type = (sc_type *) pdata; | ||
if (*type == SC_TYPE_ESPTOUCH) { | ||
printf("SC_TYPE:SC_TYPE_ESPTOUCH\n"); | ||
} else { | ||
printf("SC_TYPE:SC_TYPE_AIRKISS\n"); | ||
} | ||
break; | ||
} | ||
case SC_STATUS_LINK: { | ||
printf("SC_STATUS_LINK\n"); | ||
struct station_config *sta_conf = (station_config *) pdata; | ||
|
||
printf("Trying to connect to %s\n", sta_conf->ssid); | ||
printf("Using password to %s\n", sta_conf->password); | ||
|
||
wifi_station_set_config(sta_conf); | ||
wifi_station_disconnect(); | ||
wifi_station_connect(); | ||
|
||
// Run our method when station was connected to AP (or not connected) | ||
WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for connection timeout at start | ||
|
||
break; | ||
} | ||
case SC_STATUS_LINK_OVER: | ||
printf("SC_STATUS_LINK_OVER\n"); | ||
if (pdata != NULL) { | ||
uint8 phone_ip[4] = {0}; | ||
|
||
memcpy(phone_ip, (uint8*)pdata, 4); | ||
printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]); | ||
} | ||
smartconfig_stop(); | ||
break; | ||
} | ||
|
||
} | ||
|
||
|
||
void smartconfig_task(void *pvParameters) | ||
{ | ||
smartconfig_start(smartconfig_done); | ||
|
||
vTaskDelete(NULL); | ||
} | ||
|
||
|
||
void init() | ||
{ | ||
|
||
Serial.begin(115200); // 115200 by default | ||
Serial.systemDebugOutput(false); // Allow debug output to serial | ||
|
||
WifiAccessPoint.enable(false); | ||
WifiStation.enable(true); | ||
|
||
printf("SDK version:%s\n", system_get_sdk_version()); | ||
|
||
/* need to set opmode before you set config */ | ||
wifi_set_opmode(STATION_MODE); | ||
|
||
xTaskCreate(smartconfig_task, (const signed char*) "smartconfig_task", 256, NULL, 2, NULL); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __USER_CONFIG_H__ | ||
#define __USER_CONFIG_H__ | ||
|
||
// In this file you can define Sming Runtime parameters | ||
// For possible options see : .... | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters