Skip to content

Commit

Permalink
Merge pull request #108 from harry-boe/feature/SmartConfig
Browse files Browse the repository at this point in the history
Feature/smart config
  • Loading branch information
alonewolfx2 committed Apr 28, 2016
2 parents bbb51e7 + db6b214 commit fc50665
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 1 deletion.
24 changes: 24 additions & 0 deletions samples/Basic_SmartConfig/Makefile
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
39 changes: 39 additions & 0 deletions samples/Basic_SmartConfig/Makefile-user.mk
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

10 changes: 10 additions & 0 deletions samples/Basic_SmartConfig/README.md
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

92 changes: 92 additions & 0 deletions samples/Basic_SmartConfig/app/application.cpp
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);

}
7 changes: 7 additions & 0 deletions samples/Basic_SmartConfig/include/user_config.h
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
2 changes: 1 addition & 1 deletion sming/Makefile-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ EXTRA_INCDIR += $(SDK_BASE)/include/espressif

# libraries used in this project, mainly provided by the SDK
USER_LIBDIR = $(SMING_HOME)/compiler/lib/
LIBS = microc gcc hal phy pp net80211 wpa crypto main freertos lwip minic pwm sming
LIBS = microc gcc hal phy pp net80211 wpa crypto main freertos lwip minic pwm smartconfig sming

# compiler flags using during compilation of source files
CFLAGS = -Os -g -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
Expand Down

0 comments on commit fc50665

Please sign in to comment.