合并提交

This commit is contained in:
zogodo
2019-09-16 01:45:13 +08:00
parent 3065ffe5c7
commit a4bba1ffb3
17 changed files with 709 additions and 772 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.vs
build
zTC1.*
TC1/http_server/index.c

View File

@@ -36,8 +36,7 @@ $(NAME)_SOURCES := main.c\
user_ota.c\
user_power.c\
user_function.c\
http_server/app_httpd.c \
http_server/web_data.c
http_server/app_httpd.c
$(NAME)_COMPONENTS := protocols/SNTP\
protocols/mqtt\

View File

@@ -37,9 +37,14 @@
#include "mico.h"
#include "httpd_priv.h"
#include "app_httpd.h"
#include "user_gpio.h"
#include "main.h"
#include "web_data.c"
#define HTTP_CONTENT_HTML_ZIP "text/html\r\nContent-Encoding: gzip"
#define app_httpd_log(M, ...) custom_log("apphttpd", M, ##__VA_ARGS__)
#define HTTPD_HDR_DEFORT (HTTPD_HDR_ADD_SERVER|HTTPD_HDR_ADD_CONN_CLOSE|HTTPD_HDR_ADD_PRAGMA_NO_CACHE)
@@ -47,161 +52,243 @@ static bool is_http_init;
static bool is_handlers_registered;
struct httpd_wsgi_call g_app_handlers[];
static int web_send_wifisetting_page(httpd_request_t *req)
static int http_get_index_page(httpd_request_t *req)
{
OSStatus err = kNoErr;
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wifisetting), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisetting headers.") );
err = httpd_send_body(req->sock, wifisetting, sizeof(wifisetting));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisetting body.") );
OSStatus err = kNoErr;
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_ZIP);
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting headers."));
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting body."));
exit:
return err;
return err;
}
static int http_get_socket_status(httpd_request_t *req)
{
OSStatus err = kNoErr;
char* status = get_socket_status();
err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers.") );
err = httpd_send_body(req->sock, socket_status, strlen(status));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http socket_status body.") );
exit:
return err;
}
static int http_set_socket_status(httpd_request_t *req)
{
OSStatus err = kNoErr;
int buf_size = 512;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, save_out);
set_socket_status(buf);
char* status = "OK";
err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR);
require_noerr_action(err, save_out, app_httpd_log("ERROR: Unable to send http socket_status headers."));
err = httpd_send_body(req->sock, status, strlen(status));
require_noerr_action(err, save_out, app_httpd_log("ERROR: Unable to send http socket_status body."));
save_out:
if (buf) free(buf);
return err;
}
static int web_send_result_page(httpd_request_t *req)
{
OSStatus err = kNoErr;
bool para_succ = false;
int buf_size = 512;
char *buf;
char value_ssid[maxSsidLen];
char value_pass[maxKeyLen];
char value_user[maxNameLen];
mico_Context_t* context = NULL;
context = mico_system_context_get( );
buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr( err, Save_Out );
err = httpd_get_tag_from_post_data(buf, "SSID", value_ssid, maxSsidLen);
require_noerr( err, Save_Out );
err = httpd_get_tag_from_post_data(buf, "USER", value_user, maxNameLen);
require_noerr( err, Save_Out );
OSStatus err = kNoErr;
bool para_succ = false;
int buf_size = 512;
char *buf;
char value_ssid[maxSsidLen];
char value_pass[maxKeyLen];
char value_user[maxNameLen];
mico_Context_t* context = NULL;
context = mico_system_context_get( );
buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr( err, Save_Out );
err = httpd_get_tag_from_post_data(buf, "SSID", value_ssid, maxSsidLen);
require_noerr( err, Save_Out );
err = httpd_get_tag_from_post_data(buf, "USER", value_user, maxNameLen);
require_noerr( err, Save_Out );
if(!strncmp(value_ssid, "\0", 1))
goto Save_Out;
if(!strncmp(value_user, "\0", 1))
goto Save_Out;
strncpy(context->micoSystemConfig.ssid, value_ssid, maxSsidLen);
strncpy(user_config->user, value_user, maxNameLen);
err = httpd_get_tag_from_post_data(buf, "PASS", value_pass, maxKeyLen);
require_noerr( err, Save_Out );
strncpy(context->micoSystemConfig.key, value_pass, maxKeyLen);
strncpy(context->micoSystemConfig.user_key, value_pass, maxKeyLen);
context->micoSystemConfig.keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.user_keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.channel = 0;
memset(context->micoSystemConfig.bssid, 0x0, 6);
context->micoSystemConfig.security = SECURITY_TYPE_AUTO;
context->micoSystemConfig.dhcpEnable = true;
para_succ = true;
if(!strncmp(value_ssid, "\0", 1))
goto Save_Out;
if(!strncmp(value_user, "\0", 1))
goto Save_Out;
strncpy(context->micoSystemConfig.ssid, value_ssid, maxSsidLen);
strncpy(user_config->user, value_user, maxNameLen);
err = httpd_get_tag_from_post_data(buf, "PASS", value_pass, maxKeyLen);
require_noerr( err, Save_Out );
strncpy(context->micoSystemConfig.key, value_pass, maxKeyLen);
strncpy(context->micoSystemConfig.user_key, value_pass, maxKeyLen);
context->micoSystemConfig.keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.user_keyLength = strlen(context->micoSystemConfig.key);
context->micoSystemConfig.channel = 0;
memset(context->micoSystemConfig.bssid, 0x0, 6);
context->micoSystemConfig.security = SECURITY_TYPE_AUTO;
context->micoSystemConfig.dhcpEnable = true;
para_succ = true;
Save_Out:
if(para_succ == true)
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wifisuccess), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisuccess headers.") );
err = httpd_send_body(req->sock, wifisuccess, sizeof(wifisuccess));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisuccess body.") );
context->micoSystemConfig.configured = allConfigured;
mico_system_context_update(context);
mico_system_power_perform( context, eState_Software_Reset );
}
else
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wififail), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wififail headers.") );
err = httpd_send_body(req->sock, wififail, sizeof(wififail));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wififail body.") );
}
exit:
if(buf) free(buf);
return err;
if(para_succ == true)
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html headers.") );
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html body.") );
context->micoSystemConfig.configured = allConfigured;
mico_system_context_update(context);
mico_system_power_perform( context, eState_Software_Reset );
}
else
{
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_STR);
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html headers.") );
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http index_html body.") );
}
exit:
if(buf) free(buf);
return err;
}
static int http_wifi_config(httpd_request_t *req)
{
OSStatus err = kNoErr;
int buf_size = 512;
int ssid_size = 32;
int key_size = 64;
char *buf = malloc(buf_size);
char *wifi_ssid = malloc(ssid_size);
char *wifi_key = malloc(key_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, save_out);
err = httpd_get_tag_from_post_data(buf, "ssid", wifi_ssid, ssid_size);
require_noerr(err, save_out);
err = httpd_get_tag_from_post_data(buf, "key", wifi_key, key_size);
require_noerr(err, save_out);
wifi_connect(wifi_ssid, wifi_key);
char* status = "OK";
err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR);
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers."));
err = httpd_send_body(req->sock, status, strlen(status));
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body."));
exit:
return err;
save_out:
if (buf) free(buf);
if (ssid_size) free(ssid_size);
if (key_size) free(key_size);
return err;
}
struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, web_send_wifisetting_page, NULL, NULL, NULL},
{"/result.htm", HTTPD_HDR_DEFORT, 0, NULL, web_send_result_page, NULL, NULL},
{"/setting.htm", HTTPD_HDR_DEFORT, 0, web_send_wifisetting_page, NULL, NULL, NULL},
{"/", HTTPD_HDR_DEFORT, 0, http_get_index_page, NULL, NULL, NULL},
{"/result.htm", HTTPD_HDR_DEFORT, 0, NULL, web_send_result_page, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, http_get_socket_status, http_set_socket_status, NULL, NULL},
{"/wifi/config", HTTPD_HDR_DEFORT, 0, NULL, http_wifi_config, NULL, NULL},
};
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
static void app_http_register_handlers()
{
int rc;
rc = httpd_register_wsgi_handlers(g_app_handlers, g_app_handlers_no);
if (rc) {
app_httpd_log("failed to register test web handler");
}
int rc;
rc = httpd_register_wsgi_handlers(g_app_handlers, g_app_handlers_no);
if (rc) {
app_httpd_log("failed to register test web handler");
}
}
static int _app_httpd_start()
{
OSStatus err = kNoErr;
app_httpd_log("initializing web-services");
/*Initialize HTTPD*/
if(is_http_init == false) {
err = httpd_init();
require_noerr_action( err, exit, app_httpd_log("failed to initialize httpd") );
is_http_init = true;
}
/*Start http thread*/
err = httpd_start();
if(err != kNoErr) {
app_httpd_log("failed to start httpd thread");
httpd_shutdown();
}
OSStatus err = kNoErr;
app_httpd_log("initializing web-services");
/*Initialize HTTPD*/
if(is_http_init == false) {
err = httpd_init();
require_noerr_action( err, exit, app_httpd_log("failed to initialize httpd") );
is_http_init = true;
}
/*Start http thread*/
err = httpd_start();
if(err != kNoErr) {
app_httpd_log("failed to start httpd thread");
httpd_shutdown();
}
exit:
return err;
return err;
}
int app_httpd_start( void )
{
OSStatus err = kNoErr;
err = _app_httpd_start();
require_noerr( err, exit );
if (is_handlers_registered == false) {
app_http_register_handlers();
is_handlers_registered = true;
}
OSStatus err = kNoErr;
err = _app_httpd_start();
require_noerr( err, exit );
if (is_handlers_registered == false) {
app_http_register_handlers();
is_handlers_registered = true;
}
exit:
return err;
return err;
}
int app_httpd_stop()
{
OSStatus err = kNoErr;
/* HTTPD and services */
app_httpd_log("stopping down httpd");
err = httpd_stop();
require_noerr_action( err, exit, app_httpd_log("failed to halt httpd") );
OSStatus err = kNoErr;
/* HTTPD and services */
app_httpd_log("stopping down httpd");
err = httpd_stop();
require_noerr_action( err, exit, app_httpd_log("failed to halt httpd") );
exit:
return err;
return err;
}

View File

@@ -31,12 +31,6 @@
******************************************************************************
*/
extern const unsigned char wififail[0xAC9];
extern const unsigned char wifisetting[3618];
extern const unsigned char wifisuccess[0x9BC];
int app_httpd_start( void );
int app_httpd_stop();

310
TC1/http_server/index.html Normal file
View File

@@ -0,0 +1,310 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<title>Welcom TC1</title>
<style type="text/css">
fieldset{margin-bottom:10px;border:#000 solid 1px;}
input,select,button{padding:5px;border:#777 solid 1px;}
button{background:none;border:1px #777 solid;}
button:disabled,select:disabled,input:disabled{background:#bfbfbf;}
td{padding:5px;}
.socket input,.mode input{margin-right:-4px;}
.submit{padding:5px;margin-top:5px;}
.success{color:#58dc5c;}
.error{color:#ff2d2d;}
.info{color:#e700ea;}
.network div{padding:5px;}
.connect div{padding:5px;}
.right{text-align:right;}
.line{height:9px;border-bottom:1px solid #dedede;}
#power_div{margin-top:10px;border-left:1px solid #000;border-bottom:1px solid #000;}
#power_line{height:100px;position:relative;overflow:scroll;margin-top:-100px;}
.power_pre{position:absolute;bottom:0;float:left;height:76px;width:0;border-left:1px solid #000;border-right:1px solid #000;}
</style>
</head>
<body>
<fieldset class="socket">
<legend>Power Controll</legend>
<table id="socket_tb">
<tr>
<td>
<input type="checkbox" id="socket1" name="socket">
<label for="socket1">Socket-1</label>
</td>
<td>
<input type="checkbox" id="socket2" name="socket">
<label for="socket2">Socket-2</label>
</td>
<td>
<input type="checkbox" id="socket3" name="socket">
<label for="socket3">Socket-3</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="socket4" name="socket">
<label for="socket4">Socket-4</label>
</td>
<td>
<input type="checkbox" id="socket5" name="socket">
<label for="socket5">Socket-5</label>
</td>
<td>
<input type="checkbox" id="socket6" name="socket">
<label for="socket6">Socket-6</label>
</td>
</tr>
</table>
<div class="submit">
<button class="submit_bt" onclick="SetSocket()">Submit</button>
<span class="status_sp success">OK</span>
</div>
</fieldset>
<fieldset class="chart">
<legend>Power Status</legend>
<div id="power_div">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
<div id="power_line">
<div class="power_pre" style="height:70px;left:20px;"></div>
<div class="power_pre" style="height:75px;left:40px;"></div>
<div class="power_pre" style="height:80px;left:60px;"></div>
<div class="power_pre" style="height:85px;left:80px;"></div>
<div class="power_pre" style="height:80px;left:100px;"></div>
<div class="power_pre" style="height:75px;left:120px;"></div>
<div class="power_pre" style="height:70px;left:140px;"></div>
<div class="power_pre" style="height:65px;left:160px;"></div>
<div class="power_pre" style="height:70px;left:180px;"></div>
<div class="power_pre" style="height:75px;left:200px;"></div>
<div class="power_pre" style="height:80px;left:220px;"></div>
<div class="power_pre" style="height:85px;left:240px;"></div>
<div class="power_pre" style="height:90px;left:260px;"></div>
<div class="power_pre" style="height:85px;left:280px;"></div>
<div class="power_pre" style="height:80px;left:300px;"></div>
<div class="power_pre" style="height:78px;left:320px;"></div>
<div class="power_pre" style="height:76px;left:340px;"></div>
<div class="power_pre" style="height:72px;left:360px;"></div>
<div class="power_pre" style="height:85px;left:380px;"></div>
<div class="power_pre" style="height:80px;left:400px;"></div>
<div class="power_pre" style="height:75px;left:420px;"></div>
<div class="power_pre" style="height:70px;left:440px;"></div>
<div class="power_pre" style="height:65px;left:460px;"></div>
<div class="power_pre" style="height:70px;left:480px;"></div>
<div class="power_pre" style="height:75px;left:500px;"></div>
<div class="power_pre" style="height:80px;left:520px;"></div>
<div class="power_pre" style="height:85px;left:540px;"></div>
<div class="power_pre" style="height:90px;left:560px;"></div>
<div class="power_pre" style="height:85px;left:580px;"></div>
<div class="power_pre" style="height:80px;left:600px;"></div>
<div class="power_pre" style="height:78px;left:620px;"></div>
<div class="power_pre" style="height:76px;left:640px;"></div>
<div class="power_pre" style="height:72px;left:660px;"></div>
<div class="power_pre" style="height:85px;left:680px;"></div>
<div class="power_pre" style="height:80px;left:700px;"></div>
</div>
</fieldset>
<fieldset class="network">
<legend>Network config</legend>
<table>
<tr>
<td class="right">SSID:</td>
<td>
<select id="wifi" onchange="SelectWifi()">
<option value="0">Manual</option>
<option value="1">CMCC</option>
<option value="2">China-Net</option>
<option value="3">CMCT</option>
</select>
<button id="rescan">Rescan</button>
</td>
</tr>
<tr>
<td class="right">SSID:</td>
<td>
<input id="ssid" type="text" onchange="ChangeInput(1)"/>
</td>
</tr>
<tr>
<td class="right">PSWD:</td>
<td>
<input id="pswd" type="password" onchange="ChangeInput(2)"/>
</td>
</tr>
<tr>
<td class="right">MODE:</td>
<td class="mode">
<input type="radio" id="mode1" name="mode" onchange="ChangeMode(1)">
<label for="mode1">AP</label>
<input type="radio" id="mode2" name="mode" onchange="ChangeMode(2)">
<label for="mode2">STATION</label>
</td>
</tr>
</table>
<div class="submit">
<button class="submit_bt" onclick="SubmitNetwork()">Submit</button>
<span class="status_sp success">OK</span>
</div>
</fieldset>
<fieldset class="connect">
<legend>Connect Status</legend>
<table>
<tr>
<td class="right">IP:</td>
<td class="info">192.168.33.108</td>
</tr>
<tr>
<td class="right">Mask:</td>
<td class="info">255.255.255.0</td>
</tr>
<tr>
<td class="right">Gateway:</td>
<td class="info">192.168.33.1</td>
</tr>
</table>
</fieldset>
<script type="text/javascript">
function Ajax(url, onsuccess, type, data) {
var xml_http = new XMLHttpRequest();
xml_http.open(type, url, true);
xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xml_http.onreadystatechange = function () {
if (xml_http.readyState == 4) {
if (xml_http.status == 200) {
onsuccess(xml_http.responseText);
}
else {
alert("Ajax error: " + xml_http.status);
}
}
};
if (data != null && type == "POST") {
xml_http.send(data);
} else {
xml_http.send();
}
}
function HttpGet(url, onsuccess) {
Ajax(url, onsuccess, "GET", null);
}
function HttpPost(url, onsuccess, data) {
Ajax(url, onsuccess, "POST", data);
}
var submit_bts = document.getElementsByClassName("submit_bt");
var info_spans = document.getElementsByClassName("status_sp");
var socket_tb = document.getElementById("socket_tb");
var checkboxs = socket_tb.getElementsByTagName("input");
var rescan_btn = document.getElementById("rescan");
var ssid_slt = document.getElementById("wifi");
var ssid_ipt = document.getElementById("ssid");
var pswd_ipt = document.getElementById("pswd");
var mode_rd1 = document.getElementById("mode1");
var mode_rd2 = document.getElementById("mode2");
HttpGet("/socket", function (re) {
var status = re;
var status_arr = status.split(",");
for (var i = 0; i < status_arr.length; i++) {
checkboxs[i].checked = status_arr[i] == "1";
}
});
function SetOK(i) {
submit_bts[i].disabled = false;
info_spans[i].className = "status_sp success";
info_spans[i].innerHTML = "OK";
}
function SetIng(i) {
submit_bts[i].disabled = true;
info_spans[i].className = "status_sp info";
info_spans[i].innerHTML = "ing...";
}
function SetSocket() {
SetIng(0);
var sockets_st = "";
for (var i = 0; i < checkboxs.length; i++) {
sockets_st += (checkboxs[i].checked ? "1," : "0,");
}
HttpPost("/socket", function (re) {
SetOK(0);
}, sockets_st);
}
function SelectWifi() {
ssid_ipt.disabled = ssid_slt.value != "0";
}
var mode = 0;
var ap_name = "TC1-AP";
var ap_pswd = "12345678";
var station_name = "";
var station_pswd = "";
function ChangeMode(m) {
if (mode == m) return;
if (m == 1) {
ssid_slt.value = "0";
ssid_slt.disabled = true;
rescan_btn.disabled = true;
ssid_ipt.disabled = false;
ssid_ipt.value = ap_name;
pswd_ipt.value = ap_pswd;
} else {
ssid_slt.value = "0";
ssid_slt.disabled = false;
rescan_btn.disabled = false;
ssid_ipt.disabled = false;
ssid_ipt.value = station_name;
pswd_ipt.value = station_pswd;
}
mode = m;
}
ChangeMode(1);
mode_rd1.checked = true;
function ChangeInput(type) {
if(mode == 1) {
ap_name = ssid_ipt.value;
ap_pswd = pswd_ipt.value;
} else {
station_name = ssid_ipt.value;
station_pswd = pswd_ipt.value;
}
}
function SubmitNetwork() {
if(mode == 1) {
} else {
var params = "ssid="+station_name+"&key="+station_pswd;
HttpPost("/wifi/config", function (re) {
alert(re);
}, params);
}
}
</script>
</body>
</html>

25
TC1/http_server/test.py Normal file
View File

@@ -0,0 +1,25 @@
#! /bin/env python3
import os
import glob
import binascii
import gzip
try:
io = __import__("io").BytesIO
except:
io = __import__("StringIO").StringIO
for fn in glob.glob('*.html'):
s = open(fn, 'rb').read()
dat = io()
with gzip.GzipFile(fileobj=dat, mode="w") as f:
f.write(s)
dat = dat.getvalue()
try:
s = ','.join(["0x%02x" % c for c in dat])
except:
s = ','.join(["0x"+binascii.hexlify(c) for c in dat])
fn = fn.replace('.', '_')
print("const unsigned char %s[0x%x] = {%s};" % (fn, len(dat), s))

File diff suppressed because one or more lines are too long

View File

@@ -20,6 +20,7 @@ uint32_t power=0;
system_config_t * sys_config;
user_config_t * user_config;
char socket_status[32] = { 0 };
mico_gpio_t Relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
@@ -152,6 +153,7 @@ int application_start( void )
// }
// }
ap_init();
wifi_init( );
user_udp_init( );
key_init( );
@@ -162,7 +164,7 @@ int application_start( void )
user_power_init();
/* start http server thread */
// app_httpd_start();
app_httpd_start();
while ( 1 )
{
main_num++;

View File

@@ -2,7 +2,7 @@
#define __MAIN_H_
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
#define VERSION "v0.10.1"
@@ -72,6 +72,7 @@ extern char strMac[16];
extern uint32_t power;
extern system_config_t * sys_config;
extern user_config_t * user_config;
extern char socket_status[32];
extern mico_gpio_t Relay[Relay_NUM];

View File

@@ -4,7 +4,7 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
void user_send( int udp_flag, char *s );
void user_function_cmd_received(int udp_flag,uint8_t *pusrdata);

View File

@@ -31,35 +31,70 @@ bool relay_out( void )
return false;
}
char* get_socket_status()
{
sprintf(socket_status, "%d,%d,%d,%d,%d,%d\0",
user_config->plug[0].on,
user_config->plug[1].on,
user_config->plug[2].on,
user_config->plug[3].on,
user_config->plug[4].on,
user_config->plug[5].on);
return socket_status;
}
void set_socket_status(char* socket_status)
{
int ons[6] = { 0 };
sscanf(socket_status, "%d,%d,%d,%d,%d,%d,",
&ons[0], &ons[1], &ons[2], &ons[3], &ons[4], &ons[5]);
int i = 0;
for (i = 0; i < PLUG_NUM; i++)
{
user_relay_set(i, ons[i]);
}
}
/*user_relay_set
* <20><><EFBFBD>ü̵<C3BC><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* x:<3A><><EFBFBD><EFBFBD> 0-5
* y:<3A><><EFBFBD><EFBFBD> 0:<3A><> 1:<3A><>
* i:<3A><><EFBFBD><EFBFBD> 0-5
* on:<3A><><EFBFBD><EFBFBD> 0:<3A><> 1:<3A><>
*/
void user_relay_set(unsigned char x,unsigned char y )
void user_relay_set(unsigned char i, unsigned char on)
{
if (x >= PLUG_NUM ) return;
if (i >= PLUG_NUM) return;
if((y == 1) ? Relay_ON : Relay_OFF) MicoGpioOutputHigh( relay[x] );else MicoGpioOutputLow( relay[x] );
user_config->plug[x].on = y;
if ( relay_out( ) )
user_led_set( 1 );
if (on == Relay_ON)
{
MicoGpioOutputHigh(relay[i]);
}
else
user_led_set( 0 );
{
MicoGpioOutputLow(relay[i]);
}
user_config->plug[i].on = on;
if (relay_out())
{
user_led_set(1);
}
else
{
user_led_set(0);
}
}
/*
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м̵<D0BC><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* y:0:ȫ<><C8AB><EFBFBD><EFBFBD> 1:<3A><><EFBFBD>ݼ<EFBFBD>¼״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* y: 0:ȫ<><C8AB><EFBFBD><EFBFBD> 1:ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
*/
void user_relay_set_all( char y )
{
char i;
for ( i = 0; i < PLUG_NUM; i++ )
user_relay_set( i, y );
int i;
for (i = 0; i < PLUG_NUM; i++)
user_relay_set(i, y);
}
static void key_long_press( void )

View File

@@ -4,12 +4,13 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
extern void user_led_set(char x);
extern void key_init(void);
extern void user_relay_set(unsigned char x,unsigned char y );
extern void user_relay_set_all( char y );
extern bool relay_out( void );
void user_led_set(char x);
void key_init(void);
void user_relay_set(unsigned char x,unsigned char y );
void user_relay_set_all( char y );
bool relay_out( void );
char* get_socket_status();
#endif

View File

@@ -4,7 +4,7 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
extern OSStatus user_rtc_init(void);

View File

@@ -4,7 +4,7 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
extern void sntp_init(void);

View File

@@ -4,7 +4,7 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
OSStatus user_udp_init( void );
OSStatus user_udp_send( char *arg );

View File

@@ -59,6 +59,29 @@ void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg
micoWlanStopEasyLink( );
}
void wifi_config(char* wifi_ssid, char* wifi_key)
{
os_log("wifi_easylink_wps_completed_handle:");
if (wifi_ssid == NULL || wifi_key == NULL)
{
os_log("EasyLink fail");
micoWlanStopEasyLink();
return;
}
os_log("ssid:\"%s\",\"%s\"", wifi_ssid, wifi_ssid);
//<2F><><EFBFBD><EFBFBD>wifi<66><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
strcpy(sys_config->micoSystemConfig.ssid, wifi_ssid);
strcpy(sys_config->micoSystemConfig.user_key, wifi_key);
sys_config->micoSystemConfig.user_keyLength = strlen(wifi_key);
mico_system_context_update(sys_config);
wifi_status = WIFI_STATE_NOCONNECT;
os_log("EasyLink stop");
micoWlanStopEasyLink();
}
//wifi<66><69><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD>ȡ<EFBFBD><C8A1>IP<49><50>ַ <20>ص<EFBFBD>
static void wifi_get_ip_callback( IPStatusTypedef *pnet, void * arg )
{
@@ -92,7 +115,7 @@ static void wifi_led_timer_callback( void* arg )
mico_rtos_stop_timer( &wifi_led_timer );
break;
case WIFI_STATE_NOCONNECT:
wifi_connect_sys_config( );
//wifi_connect_sys_config( );
break;
case WIFI_STATE_CONNECTING:
@@ -119,19 +142,22 @@ static void wifi_led_timer_callback( void* arg )
}
}
void wifi_init( void )
void wifi_connect(char* wifi_ssid, char* wifi_key)
{
//wifi<66><69><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC>
// network_InitTypeDef_st wNetConfig;
network_InitTypeDef_st wNetConfig;
// memset(&wNetConfig, 0, sizeof(network_InitTypeDef_st));
// wNetConfig.wifi_mode = Station;
// snprintf(wNetConfig.wifi_ssid, 32, "Honor 9" );
// strcpy((char*)wNetConfig.wifi_key, "19910911");
// wNetConfig.dhcpMode = DHCP_Client;
// wNetConfig.wifi_retry_interval=6000;
// micoWlanStart(&wNetConfig);
memset(&wNetConfig, 0, sizeof(network_InitTypeDef_st));
wNetConfig.wifi_mode = Station;
snprintf(wNetConfig.wifi_ssid, 32, wifi_ssid);
strcpy((char*)wNetConfig.wifi_key, wifi_key);
wNetConfig.dhcpMode = DHCP_Client;
wNetConfig.wifi_retry_interval = 6000;
micoWlanStart(&wNetConfig);
}
void wifi_init( void )
{
//wifi״̬<D7B4><CCAC>led<65><64>˸<EFBFBD><CBB8>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
mico_rtos_init_timer( &wifi_led_timer, 100, (void *) wifi_led_timer_callback, NULL );
//easylink <20><><EFBFBD>ɻص<C9BB>
@@ -150,3 +176,55 @@ void wifi_init( void )
}
#define ELAND_AP_SSID "TC1-AP"
#define ELAND_AP_KEY "12345678"
#define ELAND_AP_LOCAL_IP "192.168.0.1"
#define ELAND_AP_DNS_SERVER "192.168.0.1"
#define ELAND_AP_NET_MASK "255.255.255.0"
void ap_init()
{
os_log("Soft_ap_Server");
network_InitTypeDef_st wNetConfig;
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
strcpy((char *)wNetConfig.wifi_ssid, ELAND_AP_SSID);
strcpy((char *)wNetConfig.wifi_key, ELAND_AP_KEY);
wNetConfig.wifi_mode = Soft_AP;
wNetConfig.dhcpMode = DHCP_Server;
wNetConfig.wifi_retry_interval = 100;
strcpy((char *)wNetConfig.local_ip_addr, ELAND_AP_LOCAL_IP);
strcpy((char *)wNetConfig.net_mask, ELAND_AP_NET_MASK);
strcpy((char *)wNetConfig.dnsServer_ip_addr, ELAND_AP_DNS_SERVER);
os_log("ssid:%s key:%s", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
micoWlanStart(&wNetConfig);
}
static void Wifi_SoftAP_threed(mico_thread_arg_t arg)
{
/*
network_InitTypeDef_st wNetConfig;
mico_rtos_lock_mutex(&WifiConfigMutex);
SendElandStateQueue(APServerStart);
micoWlanSuspend();
mico_rtos_thread_sleep(2);
Eland_httpd_start();
WifiSet_log("Soft_ap_Server");
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
strcpy((char *)wNetConfig.wifi_ssid, ELAND_AP_SSID);
strcpy((char *)wNetConfig.wifi_key, ELAND_AP_KEY);
wNetConfig.wifi_mode = Soft_AP;
wNetConfig.dhcpMode = DHCP_Server;
wNetConfig.wifi_retry_interval = 100;
strcpy((char *)wNetConfig.local_ip_addr, ELAND_AP_LOCAL_IP);
strcpy((char *)wNetConfig.net_mask, ELAND_AP_NET_MASK);
strcpy((char *)wNetConfig.dnsServer_ip_addr, ELAND_AP_DNS_SERVER);
WifiSet_log("ssid:%s key:%s", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
micoWlanStart(&wNetConfig);
mico_rtos_get_semaphore(&wifi_SoftAP_Sem, 5000);
mico_rtos_unlock_mutex(&WifiConfigMutex);
mico_rtos_delete_thread(NULL);
*/
}

View File

@@ -4,7 +4,7 @@
#include "mico.h"
#include "MiCOKit_EXT.h"
#include "micokit_ext.h"
enum {
@@ -21,6 +21,7 @@ enum {
extern char wifi_status;
extern void wifi_init(void);
extern void ap_init(void);
extern void wifi_start_easylink(void);