160 Commits

Author SHA1 Message Date
nhkefus
8374484d0a 去除web后台没数据时的默认值 2025-04-28 15:57:54 +08:00
Your Name
c3d9db335e 调试用 2025-04-25 11:46:19 +08:00
nhkefus
3470d373eb 尝试增加一个外网mqtt客户端 2025-04-24 13:00:44 +08:00
Your Name
3caf76f4c6 开发基于udp的app控制协议 2025-04-23 23:32:04 +08:00
Your Name
982e82c2bb v2.2.0 2025-04-21 21:30:17 +08:00
Your Name
eece61e380 修复了MQTT曾经连上,但中途长时间断开,导致消息队列一直增加爆内存,进而导致死机的问题 2025-04-21 21:29:15 +08:00
Your Name
36861fadff 修复了MQTT曾经连上,但中途长时间断开,导致消息队列一直增加爆内存,进而导致死机的问题 2025-04-21 21:17:34 +08:00
Your Name
f3b7477550 优化了web端iOS Safari按钮的一些逻辑,现在可以看到文件ota上传进度条了 2025-04-19 23:55:57 +08:00
Your Name
dfa8b1c475 现在可以连接名称带特殊符号的wifi,例如有空格 2025-04-19 18:01:14 +08:00
Your Name
c7d2f8d7d0 修复编译警告 2025-04-19 16:06:32 +08:00
Your Name
3f5078294f 修复已知问题 2025-04-18 22:35:59 +08:00
Peng
d7e2243a86 增加本地文件更新功能 2025-04-18 18:39:33 +08:00
Your Name
4e1b376b6a 本地ota加入写flash逻辑以后 会卡死。目前不知道如何优化 2025-04-18 10:12:57 +08:00
Your Name
393af288ec 补漏的代码 2025-04-17 17:52:13 +08:00
nhkefus
e9f1448a69 开发本地ota上传用的 2025-04-17 17:42:51 +08:00
nhkefus
004eaf28dd 开发本地ota上传用的 2025-04-17 17:39:27 +08:00
Your Name
0e361111a5 修复hamqtt中重启按钮无法使用的问题 2025-04-17 10:25:14 +08:00
Your Name
026e058934 修复在不配置MQTT信息的情况下,OTA将大概率无法进行,且后台可能经常卡死刷不出页面的问题 2025-04-16 23:16:01 +08:00
Your Name
5623b632c7 修复ota可能无法使用的问题 2025-04-12 16:03:34 +08:00
Your Name
34e1cabc53 修复自定义名称过长可能导致系统崩溃的问题 2025-04-09 22:53:12 +08:00
nhkefus
e6d430c37c 在HA mqtt中增加了运行时长的传感器 2025-04-03 12:51:22 +08:00
oopuuu
7c77be5455 Update README.md 2025-03-28 16:01:38 +09:00
Your Name
6598250af1 定时任务现在支持操作更多功能 2025-03-24 00:12:57 +08:00
Your Name
60977f0327 优化后台ui 2025-03-23 21:42:30 +08:00
Your Name
f1ba19554e 优化后台ui 2025-03-23 02:51:19 +08:00
Your Name
2b1577998c 修复并优化后台定时开关功能 2025-03-23 01:06:29 +08:00
Your Name
a5c9211fb6 修复并优化后台定时开关功能 2025-03-22 17:14:18 +08:00
Your Name
e735afc6c5 修复重大bug 2025-03-22 13:35:34 +08:00
oopuuu
f8d2b25d1e Update index.html
修复按钮配置,事件下拉框最后多一个空白选项的问题
2025-03-22 10:37:27 +08:00
oopuuu
a342d4552a Update README.md 2025-03-22 10:12:47 +08:00
oopuuu
759a5ec5cc Add files via upload 2025-03-22 10:12:26 +08:00
oopuuu
0ba50e9a52 Update README.md 2025-03-22 00:46:04 +08:00
oopuuu
f8fba89793 Update README.md 2025-03-22 00:40:20 +08:00
oopuuu
30a353c035 Add files via upload 2025-03-22 00:38:40 +08:00
Your Name
b470b0f8a0 支持配置多击,长按功能 2025-03-21 23:53:17 +08:00
nhkefus
76e8612007 修改按键配置相关的代码 2025-03-21 17:41:43 +08:00
nhkefus
6cf213a1b9 修改按键配置相关的代码 2025-03-21 17:38:10 +08:00
nhkefus
c214f0de30 修改按键配置相关的代码 2025-03-21 16:39:02 +08:00
nhkefus
bf7c8dd7fe 修改按键配置相关的代码 2025-03-21 16:34:19 +08:00
nhkefus
b2bd368b2d 修改按键配置相关的代码 2025-03-21 16:24:24 +08:00
nhkefus
56c9923336 修改按键配置相关的代码 2025-03-21 16:02:34 +08:00
nhkefus
2d34767cde 修改按键配置相关的代码 2025-03-21 12:51:02 +08:00
nhkefus
2258158a0d 修改按键配置相关的代码 2025-03-21 12:45:21 +08:00
nhkefus
f7b6b8ae0a 修改按键配置相关的代码 2025-03-21 12:20:49 +08:00
Your Name
b38f9f91d8 修复后台UI的问题 2025-03-20 23:28:20 +08:00
Your Name
84cf4bfc06 修复自定义按键功能的问题,修复后台UI的问题 2025-03-20 22:41:37 +08:00
oopuuu
542e5daf8a Update user_gpio.c 2025-03-20 21:27:09 +08:00
oopuuu
ceb208813a Update build.sh 2025-03-20 19:42:58 +08:00
nhkefus
fe4d037390 修复后台部分模块标题不显示的问题 2025-03-20 18:11:30 +08:00
nhkefus
8e083fe175 修改多击按钮的逻辑判断 2025-03-20 16:04:38 +08:00
nhkefus
9ac9e5e2f1 修复网页按钮配置功能UI错误 2025-03-20 15:14:20 +08:00
nhkefus
36d8330ee3 修复网页按钮配置功能UI错误 2025-03-20 14:56:08 +08:00
nhkefus
a51c7a8eb2 修复网页按钮配置功能UI错误 2025-03-20 14:44:47 +08:00
nhkefus
6ef875879f 修复网页按钮配置功能UI错误 2025-03-20 14:30:58 +08:00
nhkefus
2b2a77b5f5 修复网页按钮配置功能UI错误 2025-03-20 14:19:34 +08:00
nhkefus
787e57439e 修复网页按钮配置功能UI错误 2025-03-20 14:08:05 +08:00
nhkefus
fd157172e3 修复网页按钮配置功能UI错误 2025-03-20 14:07:07 +08:00
nhkefus
989fd0a1ed 修复网页按钮配置功能UI错误 2025-03-20 14:03:50 +08:00
oopuuu
a76afc6ccb Merge pull request #1 from wsuow/master
新增Https的测试
2025-03-20 13:41:06 +08:00
nhkefus
23fcd56109 修复网页按钮配置功能逻辑错误 2025-03-20 13:36:39 +08:00
wsuow
a6bb74f906 Merge branch 'oopuuu:master' into master 2025-03-20 12:53:32 +08:00
nhkefus
fd5d190096 在后台增加 1到10击 功能设置 2025-03-20 12:52:49 +08:00
wsuow
997eda3ef2 Merge branch 'oopuuu:master' into master 2025-03-20 12:50:51 +08:00
nhkefus
e4e0ca969e 在后台增加 1到10击 功能设置 2025-03-20 12:49:42 +08:00
wsuow
4ea9df172b Merge branch 'oopuuu:master' into master 2025-03-20 12:46:51 +08:00
nhkefus
d0a71fe216 在后台增加 1到10击 功能设置 2025-03-20 12:46:19 +08:00
wsuow
c8dd3d513d Merge branch 'oopuuu:master' into master 2025-03-20 12:34:01 +08:00
nhkefus
dd5b282c85 在后台增加 1到10击 功能设置 2025-03-20 12:31:27 +08:00
nhkefus
8acef18406 在后台增加 1到10击 功能设置 2025-03-20 12:24:46 +08:00
吴永福
13df06e546 撤销https关键字 2025-03-20 10:39:46 +08:00
wsuow
9df4b8358b Merge branch 'oopuuu:master' into master 2025-03-20 10:37:17 +08:00
吴永福
bdfed87f1e Merge branch 'master' of https://github.com/wsuow/zTC1 2025-03-20 10:22:12 +08:00
吴永福
7ea87ae4c9 增加https关键字 2025-03-20 10:21:32 +08:00
oopuuu
a87d894c4d Update user_mqtt_client.c 2025-03-19 23:42:42 +08:00
wsuow
d7e695e37e Merge branch 'oopuuu:master' into master 2025-03-19 22:48:28 +08:00
oopuuu
40bdb50a8d Update README.md 2025-03-19 22:27:30 +08:00
Your Name
caffddfb43 后台支持设备重命名 2025-03-19 22:22:17 +08:00
oopuuu
11d3d50265 Update README.md 2025-03-19 18:29:08 +08:00
nhkefus
66d2863fa4 修改固件功能说明 2025-03-19 18:27:08 +08:00
吴永福
56395f62bc 修改生成ota年月日时分秒.bin和all年月日时分秒.bin 2025-03-19 17:20:45 +08:00
wsuow
0d5ba4a7d3 Merge branch 'oopuuu:master' into master 2025-03-19 16:49:34 +08:00
nhkefus
d925c7d805 修复长按5s开启配网模式的逻辑问题 2025-03-19 16:45:09 +08:00
wsuow
b40bb1a022 Merge branch 'oopuuu:master' into master 2025-03-19 15:36:52 +08:00
nhkefus
981c33e3ad 修复后台电量显示数据错误 2025-03-19 15:16:10 +08:00
wsuow
fc631ac9f5 Merge branch 'oopuuu:master' into master 2025-03-19 14:58:12 +08:00
nhkefus
840b0eb374 修复后台电量显示数据错误 2025-03-19 14:51:20 +08:00
wsuow
f2f63625cc Merge branch 'oopuuu:master' into master 2025-03-19 14:36:17 +08:00
nhkefus
78dbc6209b 增加了童锁功能 2025-03-19 14:34:14 +08:00
wsuow
2896243e24 Merge branch 'oopuuu:master' into master 2025-03-19 14:30:44 +08:00
nhkefus
9d80970e9e 增加了童锁功能 2025-03-19 14:29:09 +08:00
wsuow
7bac9096f5 Merge branch 'oopuuu:master' into master 2025-03-19 14:21:22 +08:00
nhkefus
5f81f2ca71 增加了童锁功能 2025-03-19 14:19:09 +08:00
nhkefus
57dbe17175 在后台增加显示昨日今日耗电量 2025-03-19 12:54:01 +08:00
wsuow
a8d5319d52 Merge branch 'oopuuu:master' into master 2025-03-19 12:35:29 +08:00
nhkefus
f41a20f8d0 在后台增加显示昨日今日耗电量 2025-03-19 12:34:53 +08:00
oopuuu
52da5983b5 Update README.md 2025-03-19 12:19:48 +08:00
oopuuu
758abf123b Add files via upload 2025-03-19 12:16:36 +08:00
wsuow
e3de06437b Merge branch 'oopuuu:master' into master 2025-03-19 10:41:53 +08:00
nhkefus
7f0e5d15c8 修复已知问题 2025-03-19 10:41:02 +08:00
wsuow
7656ae998c Merge branch 'oopuuu:master' into master 2025-03-19 10:12:14 +08:00
nhkefus
3aec445e57 修复已知问题 2025-03-19 10:08:10 +08:00
wsuow
7048333ebc Merge branch 'oopuuu:master' into master 2025-03-19 09:59:08 +08:00
nhkefus
bfae22ddd6 修复已知问题 2025-03-19 09:55:47 +08:00
wsuow
520a245ef3 Merge branch 'oopuuu:master' into master 2025-03-19 08:37:27 +08:00
oopuuu
1f92b30ea0 Update user_mqtt_client.c
指定hass中的实体名称,防止新功能导致它变化
2025-03-19 00:51:44 +08:00
Your Name
4a20713693 修复插座命名功能的一些问题 2025-03-18 23:43:17 +08:00
nhkefus
b36fce48f5 修复已知编译问题 2025-03-18 13:56:24 +08:00
nhkefus
1b7d86f1f7 修复已知编译问题 2025-03-18 13:47:20 +08:00
wsuow
d7c83fa125 Merge branch 'oopuuu:master' into master 2025-03-18 13:35:48 +08:00
nhkefus
44ed1d2604 修复已知编译问题 2025-03-18 13:27:03 +08:00
wsuow
f17ca68404 Merge branch 'oopuuu:master' into master 2025-03-18 13:13:41 +08:00
nhkefus
b5cb7b8218 在后台增加6个开关重命名功能,名称将同步到ha mqtt设备中 2025-03-18 13:01:05 +08:00
oopuuu
b099618b91 Update README.md 2025-03-17 20:34:34 +08:00
oopuuu
160f4f5b7f Update README.md 2025-03-17 20:33:20 +08:00
oopuuu
168f89cc82 Add files via upload 2025-03-17 20:31:50 +08:00
wsuow
713dd1a907 Merge branch 'oopuuu:master' into master 2025-03-17 14:12:17 +08:00
nhkefus
59d8809641 修复总开关逻辑问题 2025-03-17 14:08:26 +08:00
wsuow
8537240bbd Merge branch 'oopuuu:master' into master 2025-03-17 13:57:40 +08:00
nhkefus
f1e15500e4 修复总开关逻辑问题 2025-03-17 13:57:08 +08:00
wsuow
5a1b82b728 Merge branch 'oopuuu:master' into master 2025-03-17 13:47:51 +08:00
nhkefus
f56beae55e 修复总开关逻辑问题 2025-03-17 13:44:35 +08:00
wsuow
9caeec8611 Merge branch 'oopuuu:master' into master 2025-03-17 13:22:10 +08:00
nhkefus
65d6c77a1e 修复总开关逻辑问题 2025-03-17 13:21:52 +08:00
wsuow
8a28029940 Merge branch 'oopuuu:master' into master 2025-03-17 13:14:48 +08:00
nhkefus
56f8a2efaa 修复总开关逻辑问题 2025-03-17 13:14:07 +08:00
wsuow
3964703152 Merge branch 'oopuuu:master' into master 2025-03-17 13:10:41 +08:00
nhkefus
b2b9152441 修复总开关逻辑问题 2025-03-17 13:10:04 +08:00
wsuow
4b000d109c Merge branch 'oopuuu:master' into master 2025-03-17 13:07:18 +08:00
nhkefus
6f6c1b700f 修复总开关逻辑问题 2025-03-17 11:38:48 +08:00
wsuow
90ba74b401 Merge branch 'oopuuu:master' into master 2025-03-17 11:16:27 +08:00
nhkefus
c49fc46e15 后台以及ha mqtt增加总开关功能 2025-03-17 10:43:37 +08:00
nhkefus
7113b361e8 后台以及ha mqtt增加总开关功能 2025-03-17 10:40:45 +08:00
oopuuu
a3e3639cf9 Update main.c 2025-03-16 14:38:42 +08:00
oopuuu
d0ff87c8d0 Update main.c 2025-03-16 14:37:17 +08:00
Your Name
b3a074d4c3 修复日耗电量统计的错误,mqtt中增加了TC1设备,传感器和开关现在归属在设备下 2025-03-14 21:35:45 +08:00
oopuuu
a639b58922 Update user_mqtt_client.c
向ha mqtt增加设备,而不是只增加实体
2025-03-14 23:12:06 +08:00
wsuow
208a7b3ef9 Merge branch 'oopuuu:master' into master 2025-03-14 12:53:22 +08:00
nhkefus
9e26335841 调试 2025-03-14 12:51:42 +08:00
wsuow
ba943fe6ae Merge branch 'oopuuu:master' into master 2025-03-14 12:48:35 +08:00
nhkefus
20d3c98bb4 调试 2025-03-14 11:49:51 +08:00
nhkefus
c27b89b82d 调试 2025-03-14 11:47:24 +08:00
wsuow
3fca5b51aa Merge branch 'oopuuu:master' into master 2025-03-14 11:21:48 +08:00
nhkefus
3070e5139f 调试 2025-03-14 11:21:25 +08:00
wsuow
daa3415717 Merge branch 'oopuuu:master' into master 2025-03-14 10:47:21 +08:00
nhkefus
a10788abeb 调试 2025-03-14 09:42:04 +08:00
nhkefus
c88fb23dfe 调试 2025-03-14 09:41:20 +08:00
wsuow
e7d380bf4c Merge branch 'oopuuu:master' into master 2025-03-13 10:55:31 +08:00
nhkefus
997c8695ab 调试 2025-03-13 10:54:56 +08:00
wsuow
eb7241e235 Merge branch 'oopuuu:master' into master 2025-03-13 10:31:51 +08:00
nhkefus
09a36dc351 调试 2025-03-13 09:56:55 +08:00
oopuuu
e6e46bdf39 Update main.c 2025-03-13 09:04:56 +08:00
oopuuu
24188e39c9 Update README.md 2025-03-12 14:42:13 +08:00
oopuuu
b9e6b02217 Update README.md 2025-03-12 14:19:42 +08:00
wsuow
3350aa5446 Merge branch 'oopuuu:master' into master 2025-03-12 08:40:13 +08:00
oopuuu
9f83fbd744 Update main.c
再次修改日电量统计逻辑
2025-03-12 00:49:15 +08:00
Your Name
51817d6b6a Merge branch 'master' of github.com:oopuuu/zTC1 2025-03-11 23:30:02 +08:00
Your Name
ad5f3ecf96 在hass mqtt中增加LED的开关 2025-03-11 23:26:59 +08:00
oopuuu
4e34a88be6 Update README.md 2025-03-11 20:11:01 +08:00
吴永福
c94e8fcd12 修复mico-os SDK库错误 2025-03-11 17:21:17 +08:00
吴永福
4ed9dbd435 更改README.md 2025-03-11 16:31:55 +08:00
40 changed files with 3633 additions and 1368 deletions

125
.cproject Normal file
View File

@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.2123886510">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.2123886510" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.2123886510" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.2123886510." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1020810961" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1020810961.1245561758" name=""/>
<builder buildPath="${ProjDirPath}/" command="${ProjDirPath}/make.exe" id="org.eclipse.cdt.build.core.settings.default.builder.1574076724" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1419411456" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1269034716" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.2077730760" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.416463984" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1802293645" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.545607982" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1775218918" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="MiCO-3-0.null.804040427" name="MiCO-3-0"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.2123886510">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1826818492">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/MiCO-3-0"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="helloworld@MK3165 total download" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildArguments/>
<buildTarget>helloworld@MK3165 total download</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="helloworld@MK3165" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make</buildCommand>
<buildArguments/>
<buildTarget>helloworld@MK3165</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="standard release" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildTarget>standard release</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="helloworld@MK3165 total" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildArguments/>
<buildTarget>helloworld@MK3165 total</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="bluetooth.ble_hello_sensor@MK3238" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildArguments/>
<buildTarget>bluetooth.ble_hello_sensor@MK3238</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="bluetooth.ble_hello_sensor@MK3238 total" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildArguments/>
<buildTarget>bluetooth.ble_hello_sensor@MK3238 total</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="bluetooth.ble_hello_sensor@MK3238 total download" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${ProjDirPath}/make.exe</buildCommand>
<buildArguments/>
<buildTarget>bluetooth.ble_hello_sensor@MK3238 total download</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

2
.gdbinit Normal file
View File

@@ -0,0 +1,2 @@
set remotetimeout 20
shell start /B F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt

3
.openocd_cfg Normal file
View File

@@ -0,0 +1,3 @@
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/jlink_swd.cfg]
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx.cfg]
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]

27
.project Normal file
View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zTC1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>cleanfullincremental</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>fullincremental</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

1
.version Normal file
View File

@@ -0,0 +1 @@
v1.0.79

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "e:/15_GitHub/TC1/zTC1/TC1",
"program": "e:/15_GitHub/TC1/zTC1/TC1/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

View File

@@ -8,10 +8,10 @@
# 固件web界面
<img src="doc/2.png"><img src="doc/1.png">
<img src="doc/IMG_0863.png"><img src="doc/1.png"><img src="doc/IMG_0887.png">
# HASS接入效果
<img src="doc/3.png">
<img src="doc/IMG_0888.png">
固件启动后, 会开启一个热点 TC1-AP-XXXXXX连接热点后, 直接用浏览器访问: http://192.168.0.1 即可看到如上web界面.
@@ -52,17 +52,27 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
- [x] HomeAssistant中增加总耗电量传感器今日耗电量传感器昨日耗电量传感器数据来自于插座历史统计
- [x] 可以设置mqtt数据上报频率默认2秒
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
- [x] 后台和ha mqtt增加总开关控制
- [x] 后台可以自定义6个插座的名称名称将会自动同步到ha mqtt
- [x] 修复了原代码中电源按钮长按 (现在是5秒)重新配网和(10秒)恢复出厂的逻辑错误
- [x] 后台和ha mqtt中增加了童锁开关开启童锁则上电以后不再响应任何电源按钮的事件**上电时同时按住按钮的话会开启配网热点**防止开了童锁wifi又嗝屁导致插座功能暴毙的救命逻辑
- [x] 后台可自定义设备名称此名称将会同至ha mqtt作为mqtt中插座名称的前缀
- [x] 后台可自定义按键连击,长按等功能
- [x] 定时开关现在支持更多操作项,与按键功能自定义一样
# 编译固件
- windows环境先安装python2.7
- 安装[mico-cube 1.0.0](https://files.pythonhosted.org/packages/a8/4e/687a3ef2edabfd9fdd797747d6eeb2ddbe70e65c49fa4062268281a0ded4/mico-cube-1.0.0.tar.gz#sha256=4a930d394344f72c862c203d5d8a832357c3b3dc940c825ca3e528453dd2f17f)
- windows环境先安装python2.7,下载安装的时候添加环境变量到Path默认安装路径需要添加两个环境变量C:\Python27C:\Python27\Scripts
- 安装[mico-cube 1.0.0](https://files.pythonhosted.org/packages/a8/4e/687a3ef2edabfd9fdd797747d6eeb2ddbe70e65c49fa4062268281a0ded4/mico-cube-1.0.0.tar.gz#sha256=4a930d394344f72c862c203d5d8a832357c3b3dc940c825ca3e528453dd2f17f) python2 -m pip install ./mico-cube-1.0.0.tar.gz
- 安装[Micoder](http://firmware.mxchip.com/MiCoder_v1.3_Win32:64.zip)下载完解压出来(不要有中文路径)
- 安装完成后添加micoder路径 mico config --global MICODER (micoder所在路径)/MiCoder
- 最后切换到此项目根目录执行build.sh即可编译固件
# 注意事项
- 使用pip安装mico-cube失败请使用下列命令安装执行命令时注意路径位置
- `python -m pip install mico-cube-1.0.0.tar.gz`

View File

@@ -19,7 +19,7 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################
###############################################################################
NAME := App_TC1
@@ -34,7 +34,8 @@ $(NAME)_SOURCES := main.c\
user_power.c\
timed_task/timed_task.c\
http_server/web_log.c\
http_server/app_httpd.c
http_server/app_httpd.c\
udp_server/udp_server.c
$(NAME)_COMPONENTS := protocols/SNTP\
protocols/mqtt\

View File

@@ -36,6 +36,11 @@
#include <http-strings.h>
#include "stdlib.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mico.h"
#include "httpd_priv.h"
#include "app_httpd.h"
@@ -52,8 +57,11 @@
static bool is_http_init;
static bool is_handlers_registered;
const struct httpd_wsgi_call g_app_handlers[];
char power_info_json[1552] = {0};
char power_info_json[2560] = {0};
char up_time[16] = "00:00:00";
#define CHUNK_SIZE 512 // 每次发送 512 字节,避免 buffer 太大
#define OTA_BUFFER_SIZE 512
#define MAX_OTA_SIZE 1024*1024
/*
void GetPraFromUrl(char* url, char* pra, char* val)
@@ -90,27 +98,30 @@ void GetPraFromUrl(char* url, char* pra, char* val)
}
*/
static int HttpGetIndexPage(httpd_request_t *req) {
static OSStatus send_in_chunks(int sock, const uint8_t *data, int total_len) {
OSStatus err = kNoErr;
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index headers."));
err = httpd_send_body(req->sock, web_index_html, sizeof(web_index_html));
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index body."));
exit:
for (int offset = 0; offset < total_len; offset += CHUNK_SIZE) {
int chunk_len = (total_len - offset > CHUNK_SIZE) ? CHUNK_SIZE : (total_len - offset);
err = httpd_send_body(sock, data + offset, chunk_len);
require_noerr_action(err, exit, http_log("ERROR: Send chunk failed at offset %d", offset));
}
exit:
return err;
}
static int HttpGetDemoPage(httpd_request_t *req) {
static int HttpGetIndexPage(httpd_request_t *req) {
OSStatus err = kNoErr;
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
require_noerr_action(err, exit, http_log("ERROR: Unable to send http demo headers."));
int total_sz = sizeof(web_index_html);
err = httpd_send_body(req->sock, web_index_html, sizeof(web_index_html));
require_noerr_action(err, exit, http_log("ERROR: Unable to send http demo body."));
exit:
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, HTTP_CONTENT_HTML_ZIP);
require_noerr_action(err, exit, http_log("ERROR: Unable to send index headers."));
err = send_in_chunks(req->sock, web_index_html, total_sz);
require_noerr_action(err, exit, http_log("ERROR: Unable to send index body."));
exit:
return err;
}
@@ -118,14 +129,15 @@ static int HttpGetAssets(httpd_request_t *req) {
OSStatus err = kNoErr;
char *file_name = strstr(req->filename, "/assets/");
if (!file_name) { http_log("HttpGetAssets url[%s] err", req->filename);
if (!file_name) {
http_log("HttpGetAssets url[%s] err", req->filename);
return err;
}
//http_log("HttpGetAssets url[%s] file_name[%s]", req->filename, file_name);
int total_sz = 0;
const unsigned char *file_data = NULL;
const char *content_type = HTTP_CONTENT_JS_ZIP;
if (strcmp(file_name + 8, "js_pack.js") == 0) {
total_sz = sizeof(js_pack);
file_data = js_pack;
@@ -133,34 +145,53 @@ static int HttpGetAssets(httpd_request_t *req) {
total_sz = sizeof(css_pack);
file_data = css_pack;
content_type = HTTP_CONTENT_CSS_ZIP;
} else if (strcmp(file_name + 8, "index.html") == 0) {
total_sz = sizeof(web_index_html);
file_data = web_index_html;
content_type = HTTP_CONTENT_HTML_ZIP;
}
if (total_sz == 0 || file_data == NULL) {
http_log("File not found: %s", req->filename);
return err;
}
if (total_sz == 0) return err;
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, content_type);
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets headers."));
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset headers."));
err = httpd_send_body(req->sock, file_data, total_sz);
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets body."));
err = send_in_chunks(req->sock, file_data, total_sz);
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset body."));
exit:
exit:
return err;
}
static int HttpGetTc1Status(httpd_request_t *req) {
char *sockets = GetSocketStatus();
char *tc1_status = malloc(512);
char *short_click_config = GetButtonClickConfig();
char *tc1_status = malloc(1500);
char *socket_names = malloc(512);
sprintf(socket_names, "%s,%s,%s,%s,%s,%s",
user_config->socket_names[0],
user_config->socket_names[1],
user_config->socket_names[2],
user_config->socket_names[3],
user_config->socket_names[4],
user_config->socket_names[5]);
sprintf(tc1_status, TC1_STATUS_JSON, sockets, ip_status.mode,
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT,
MQTT_SERVER_USR, MQTT_SERVER_PWD,
VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, user_config->mqtt_report_freq,
user_config->power_led_enabled, 0L);
user_config->power_led_enabled, 0L, socket_names, childLockEnabled,
sys_config->micoSystemConfig.name, short_click_config);
OSStatus err = kNoErr;
send_http(tc1_status, strlen(tc1_status), exit, &err);
exit:
if (socket_names) free(socket_names);
if (tc1_status) free(tc1_status);
return err;
}
@@ -183,6 +214,179 @@ static int HttpSetSocketStatus(httpd_request_t *req) {
return err;
}
static int HttpSetSocketName(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 70;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
int index;
char name[64];
sscanf(buf, "%d %s", &index, name);
strcpy(user_config->socket_names[index], name);
mico_system_context_update(sys_config);
registerMqttEvents();
send_http("OK", 2, exit, &err);
exit:
if (buf) free(buf);
return err;
}
static int HttpSetButtonEvent(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 10;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
int index;
int func;
int longPress;
sscanf(buf, "%d %d %d", &index, &func, &longPress);
if (longPress == 1) {
set_key_map(user_config->user,index, get_short_func(user_config->user[index]), func == -1 ? NO_FUNCTION : func);
} else {
set_key_map(user_config->user,index, func == -1 ? NO_FUNCTION : func, get_long_func(user_config->user[index]));
}
key_log("WARNGIN:set KEY func %d %d %d", index,get_short_func(user_config->user[index]),get_long_func(user_config->user[index]));
mico_system_context_update(sys_config);
send_http("OK", 2, exit, &err);
exit:
if (buf) free(buf);
return err;
}
#define OTA_BUF_SIZE 5120
static int HttpSetOTAFile(httpd_request_t *req)
{
tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d, req.chunked=%d",
req->hdr_parsed, req->remaining_bytes, req->body_nbytes, req->chunked);
OSStatus err = kNoErr;
int total = 0;
int ret = 0;
// req->chunked = 1;
int total1 = req->remaining_bytes;
char *buffer = malloc(OTA_BUF_SIZE);
if (!buffer) return kNoMemoryErr;
uint32_t offset = 0;
mico_logic_partition_t* ota_partition = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
CRC16_Context crc_context;
CRC16_Init(&crc_context);
// 尝试读取全部 POST 数据
while (1) {
ret = httpd_get_data2(req, buffer,OTA_BUF_SIZE);
// ret = httpd_recv(req->sock, buffer, 128, 0);
total += ret;
// req->remaining_bytes -= ret;
if (ret > 0) {
CRC16_Update(&crc_context, buffer, ret);
err = MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (uint8_t *)buffer, ret);
require_noerr_quiet(err, exit);
tc1_log("[OTA] 本次读取 %d 字节,累计 %d 字节", ret, total);
}
if (ret == 0 || req->remaining_bytes <= 0) {
// 读取完毕
tc1_log("[OTA] 数据读取完成, 总计 %d 字节", total);
break;
} else if (ret < 0) {
tc1_log("[OTA] 数据读取失败, ret=%d", ret);
err = kConnectionErr;
break;
}
mico_rtos_thread_msleep(100);
// tc1_log("[OTA] %x", buffer);
// tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d",
// req->hdr_parsed, req->remaining_bytes, req->body_nbytes);
}
// if (buffer) free(buffer);
uint16_t crc16;
CRC16_Final(&crc_context, &crc16);
err = mico_ota_switch_to_new_fw(total, crc16);
tc1_log("[OTA] mico_ota_switch_to_new_fw err=%d", err);
require_noerr(err, exit);
char resp[128];
snprintf(resp, sizeof(resp), "OK, total: %d bytes, req %d %d", total, req->body_nbytes, total1);
send_http(resp, strlen(resp), exit, &err);
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
exit:
if (buffer) free(buffer);
return err;
// ota_file_req = req;
// OSStatus err = kNoErr;
// err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "OtaFileThread", OtaFileThread, 0x1000, 0);
// char buf[16] = {0};
// sprintf(buf, "%d", sizeof(ota_file_req));
// send_http(buf, strlen(buf), exit, &err);
// exit:
// if (buf) free(buf);
// return err;
}
static int HttpSetDeviceName(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 70;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
char name[64];
sscanf(buf, "%s", name);
strcpy(sys_config->micoSystemConfig.name, name);
mico_system_context_update(sys_config);
registerMqttEvents();
send_http("OK", 2, exit, &err);
exit:
if (buf) free(buf);
return err;
}
static int HttpSetChildLock(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 32;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
int enableLock;
sscanf(buf, "%d", &enableLock);
user_config->user[0] = enableLock;
childLockEnabled = enableLock;
mico_system_context_update(sys_config);
UserMqttSendChildLockState();
send_http("OK", 2, exit, &err);
exit:
if (buf) free(buf);
return err;
}
static int HttpGetPowerInfo(httpd_request_t *req) {
OSStatus err = kNoErr;
char buf[16];
@@ -204,9 +408,21 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
char *powers = GetPowerRecord(idx);
char *sockets = GetSocketStatus();
char *short_click_config = GetButtonClickConfig();
char *socket_names = malloc(512);
sprintf(socket_names, "%s,%s,%s,%s,%s,%s",
user_config->socket_names[0],
user_config->socket_names[1],
user_config->socket_names[2],
user_config->socket_names[3],
user_config->socket_names[4],
user_config->socket_names[5]);
sprintf(power_info_json, POWER_INFO_JSON, sockets, power_record.idx, PW_NUM, p_count, powers,
up_time,user_config->power_led_enabled);
up_time, user_config->power_led_enabled, RelayOut() ? 1 : 0, socket_names,
user_config->p_count_1_day_ago, user_config->p_count_2_days_ago, childLockEnabled,
sys_config->micoSystemConfig.name, short_click_config);
send_http(power_info_json, strlen(power_info_json), exit, &err);
if (socket_names) free(socket_names);
exit:
return err;
}
@@ -219,19 +435,62 @@ static int HttpGetWifiConfig(httpd_request_t *req) {
return err;
}
// 单个十六进制字符转数字(安全)
static int hex_char_to_int(char c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
if ('A' <= c && c <= 'F') return c - 'A' + 10;
return -1;
}
// 健壮版 URL 解码函数
void url_decode(const char *src, char *dest, size_t max_len) {
size_t i = 0;
while (*src && i < max_len - 1) {
if (*src == '%') {
if (isxdigit((unsigned char)src[1]) && isxdigit((unsigned char)src[2])) {
int high = hex_char_to_int(src[1]);
int low = hex_char_to_int(src[2]);
if (high >= 0 && low >= 0) {
dest[i++] = (char)((high << 4) | low);
src += 3;
continue;
}
}
// 非法编码,跳过 %
src++;
} else if (*src == '+') {
dest[i++] = ' ';
src++;
} else {
dest[i++] = *src++;
}
}
dest[i] = '\0';
}
static int HttpSetWifiConfig(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 97;
char *buf = malloc(buf_size);
int mode = -1;
char *wifi_ssid = malloc(32);
char *wifi_key = malloc(32);
char *buf = malloc(256);
char *ssid_enc = malloc(128);
char *key_enc = malloc(128);
char *wifi_ssid = malloc(128);
char *wifi_key = malloc(128);
int mode = -1;
err = httpd_get_data(req, buf, buf_size);
err = httpd_get_data(req, buf, 256);
require_noerr(err, exit);
sscanf(buf, "%d %s %s", &mode, wifi_ssid, wifi_key);
// 假设 httpd_get_data(req, buf, 256);
// tc1_log("wifi config %s",buf);
sscanf(buf, "%d %s %s", &mode, ssid_enc, key_enc);
// tc1_log("wifi config %s %s",ssid_enc,key_enc);
url_decode(ssid_enc, wifi_ssid,128);
url_decode(key_enc, wifi_key,128);
// tc1_log("wifi config decode %s %s",wifi_ssid,wifi_key);
if (mode == 1) {
WifiConnect(wifi_ssid, wifi_key);
} else {
@@ -291,7 +550,10 @@ static int HttpSetMqttConfig(httpd_request_t *req) {
sscanf(buf, "%s %d %s %s", MQTT_SERVER, &MQTT_SERVER_PORT, MQTT_SERVER_USR, MQTT_SERVER_PWD);
mico_system_context_update(sys_config);
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
err = UserMqttInit();
require_noerr(err, exit);
}
send_http("OK", 2, exit, &err);
exit:
@@ -328,6 +590,7 @@ static int HttpGetMqttReportFreq(httpd_request_t *req) {
send_http(freq, strlen(freq), exit, &err);
exit:
if (freq) free(freq);
return err;
}
@@ -350,12 +613,21 @@ static int HttpGetTasks(httpd_request_t *req) {
return err;
}
static int HttpGetButtonEvents(httpd_request_t *req) {
OSStatus err = kNoErr;
char *clicks = GetButtonClickConfig();
send_http(clicks, strlen(clicks), exit, &err);
exit:
return err;
}
static int HttpAddTask(httpd_request_t *req) {
OSStatus err = kNoErr;
//1577369623 4 0
char buf[16] = {0};
err = httpd_get_data(req, buf, 16);
char buf[20] = {0};
err = httpd_get_data(req, buf, 20);
require_noerr(err, exit);
pTimedTask task = NewTask();
@@ -364,20 +636,19 @@ static int HttpAddTask(httpd_request_t *req) {
send_http(mess, strlen(mess), exit, &err);
return err;
}
int re = sscanf(buf, "%ld %d %d %d", &task->prs_time, &task->socket_idx, &task->on,
int re = sscanf(buf, "%ld %d %d %d", &task->prs_time, &task->operation, &task->on,
&task->weekday);http_log("AddTask buf[%s] re[%d] (%ld %d %d %d)",
buf, re, task->prs_time, task->socket_idx, task->on,
buf, re, task->prs_time, task->operation, task->on,
task->weekday);
task->socket_idx--;
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|| task->socket_idx < 0 || task->socket_idx > 5
|| (task->on != 0 && task->on != 1)) { http_log("AddTask Error!");
|| task->operation < 0 || task->operation > 11) { http_log("AddTask Error!");
re = 0;
}
char *mess = (re == 4 && AddTask(task)) ? "OK" : "NO";
send_http(mess, strlen(mess), exit, &err);
exit:
return err;
}
@@ -409,6 +680,7 @@ static int LedStatus(httpd_request_t *req) {
send_http(led, strlen(led), exit, &err);
exit:
if (led) free(led);
return err;
}
@@ -427,6 +699,7 @@ static int LedSetEnabled(httpd_request_t *req) {
} else {
UserLedSet(0);
}
UserMqttSendLedState();
mico_system_context_update(sys_config);
send_http("OK", 2, exit, &err);
@@ -436,6 +709,30 @@ static int LedSetEnabled(httpd_request_t *req) {
return err;
}
static int TotalSocketSetEnabled(httpd_request_t *req) {
OSStatus err = kNoErr;
int buf_size = 97;
int on;
char *buf = malloc(buf_size);
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
sscanf(buf, "%d", &on);
UserRelaySetAll(on);
int i = 0;
for (; i < SOCKET_NUM; i++) {
UserMqttSendSocketState(i);
}
UserMqttSendTotalSocketState();
send_http("OK", 2, exit, &err);
exit:
if (buf) free(buf);
return err;
}
static int Otastatus(httpd_request_t *req) {
OSStatus err = kNoErr;
char buf[16] = {0};
@@ -461,7 +758,6 @@ static int OtaStart(httpd_request_t *req) {
const struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
{"/demo", HTTPD_HDR_DEFORT, 0, HttpGetDemoPage, NULL, NULL, NULL},
{"/assets", HTTPD_HDR_ADD_SERVER |
HTTPD_HDR_ADD_CONN_CLOSE, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetAssets, NULL, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
@@ -476,6 +772,12 @@ const struct httpd_wsgi_call g_app_handlers[] = {
{"/task", HTTPD_HDR_DEFORT, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetTasks, HttpAddTask, NULL, HttpDelTask},
{"/ota", HTTPD_HDR_DEFORT, 0, Otastatus, OtaStart, NULL, NULL},
{"/led", HTTPD_HDR_DEFORT, 0, LedStatus, LedSetEnabled, NULL, NULL},
{"/socketAll", HTTPD_HDR_DEFORT, 0, NULL, TotalSocketSetEnabled, NULL, NULL},
{"/socketNames", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketName, NULL, NULL},
{"/childLock", HTTPD_HDR_DEFORT, 0, NULL, HttpSetChildLock, NULL, NULL},
{"/deviceName", HTTPD_HDR_DEFORT, 0, NULL, HttpSetDeviceName, NULL, NULL},
{"/buttonEvents", HTTPD_HDR_DEFORT, 0, HttpGetButtonEvents, HttpSetButtonEvent, NULL, NULL},
{"/ota/fileUpload", HTTPD_HDR_DEFORT, 0, NULL, HttpSetOTAFile, NULL, NULL},
};
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);

View File

@@ -64,12 +64,16 @@
'gateway':'%s',\
'reportFreq':'%d',\
'ledEnabled':%d,\
'up_time':%ld\
'up_time':%ld,\
'socketNames':'%s',\
'child_lock_enabled':%d,\
'deviceName':'%s',\
'btnClicks':%s\
}"
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d}"
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%d,'p_count_2_days_ago':%d,'child_lock_enabled':%d,'deviceName':'%s','btnClicks':%s}"
int AppHttpdStart(void);
extern int AppHttpdStart(void);
int AppHttpdStop();
extern int AppHttpdStop();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "mico.h"
#include"http_server/web_log.h"
@@ -36,6 +38,9 @@ char* GetLogRecord()
tmp += strlen(tmp);
if (!log_record.logs[i%LOG_NUM]) continue;
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
if(i == log_record.idx){
sprintf(tmp, "%s\nFreeMem %d bytes\n",log_record.logs[i%LOG_NUM],MicoGetMemoryInfo()->free_memory);
}
}
return log_record_str;
}

View File

@@ -4,18 +4,21 @@
#include "time.h"
#include "unistd.h"
#include "TimeUtils.h"
#include "mico_system.h"
#include "user_gpio.h"
#include "user_wifi.h"
#include "time_server/user_rtc.h"
#include "user_power.h"
#include "mqtt_server/user_mqtt_client.h"
#include "http_server/app_httpd.h"
#include "udp_server/udp_server.h"
#include "timed_task/timed_task.h"
char rtc_init = 0; //sntp校时成功标志位
uint32_t total_time = 0;
char str_mac[16] = {0};
int last_check_day = 0;
int childLockEnabled = 0;
system_config_t *sys_config;
user_config_t *user_config;
@@ -42,12 +45,23 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
userConfigDefault->p_count_1_day_ago = 0;
userConfigDefault->power_led_enabled = 1;
userConfigDefault->version = USER_CONFIG_VERSION;
int i;
for (i = 0; i < SOCKET_NUM; i++) {
userConfigDefault->socket_status[i] = 1;
set_key_map(userConfigDefault->user,1, SWITCH_ALL_SOCKETS, NO_FUNCTION);
for (int i = 2; i < 32; i++) {
int longFunc = NO_FUNCTION;
//出厂设置长按5秒开启配网模式长按10秒恢复出厂设置
if (i >=5 && i< 10) {
longFunc = CONFIG_WIFI;
} else if (i >= 10 && i< 15) {
longFunc = RESET_SYSTEM;
}
set_key_map(userConfigDefault->user,i, NO_FUNCTION, longFunc);
}
for (i = 0; i < MAX_TASK_NUM; i++) {
for (int i = 0; i < SOCKET_NUM; i++) {
userConfigDefault->socket_status[i] = 1;
snprintf(userConfigDefault->socket_names[i], SOCKET_NAME_LENGTH, "插座-%d", i + 1);
}
for (int i = 0; i < MAX_TASK_NUM; i++) {
userConfigDefault->timed_tasks[i].on_use = false;
}
mico_system_context_update(sys_config);
@@ -55,19 +69,38 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
void recordDailyPCount() {
// 获取当前时间
time_t now;
time(&now);
struct tm *current_time = localtime(&now);
if (current_time->tm_hour != 0 || current_time->tm_min != 0) {
return;
mico_utc_time_t utc_time;
mico_time_get_utc_time(&utc_time);
utc_time += 28800;
struct tm *current_time = localtime((const time_t *) &utc_time);
// 判断上次检查的时间与当前时间的日期是否不同
if (last_check_day != 0) {
// 如果日期发生变化(即跨天了),则进行记录
if (current_time->tm_mday != last_check_day) { tc1_log(
"WARNGIN: pcount day changed! now day %d hour %d min %d ,lastCheck day %d",
current_time->tm_mday, current_time->tm_hour, current_time->tm_min,
last_check_day);
// tc1_log("WARNGIN: pcount day changed! ");
// 记录数据
if (user_config->p_count_1_day_ago != 0) {
user_config->p_count_2_days_ago = user_config->p_count_1_day_ago;
}
user_config->p_count_1_day_ago = p_count;
// 更新系统配置
mico_system_context_update(sys_config);
tc1_log("WARNGIN: p_count record! p_count_1_day_ago:%d p_count_2_days_ago:%d",
user_config->p_count_1_day_ago, user_config->p_count_2_days_ago);
} else {
// tc1_log("WARNGIN: pcount day not changed , waiting for next run! ");
}
} else { tc1_log("WARNGIN: now day %d hour %d min %d ,lastCheck day %d", current_time->tm_mday,
current_time->tm_hour, current_time->tm_min, last_check_day);
}
if (user_config->p_count_1_day_ago != 0) {
user_config->p_count_2_days_ago = user_config->p_count_1_day_ago;
}
user_config->p_count_1_day_ago = p_count;
mico_system_context_update(sys_config);tc1_log(
"WARNGIN: p_count record! p_count_1_day_ago:%d p_count_2_days_ago:%d",
user_config->p_count_1_day_ago, user_config->p_count_2_days_ago);
// 更新上次检查时间
last_check_day = current_time->tm_mday;
}
void schedule_p_count_task(mico_thread_arg_t arg) {
@@ -105,8 +138,6 @@ int application_start(void) {
err = mico_system_init(sys_config);
require_noerr(err, exit);
p_count = user_config->p_count_1_day_ago;
uint8_t mac[8];
mico_wlan_get_mac_address(mac);
sprintf(str_mac, "%02X%02X%02X%02X%02X%02X",
@@ -116,7 +147,7 @@ int application_start(void) {
MicoGpioInitialize((mico_gpio_t) Button, INPUT_PULL_UP);
if (!MicoGpioInputGet(Button)) { //开机时按钮状态
tc1_log("press ap_init");
ApInit(false);
ApInit(true);
open_ap = true;
}
@@ -127,6 +158,7 @@ int application_start(void) {
}
MicoSysLed(0);
childLockEnabled = (int) user_config->user[0];
if (user_config->version != USER_CONFIG_VERSION) { tc1_log("WARNGIN: user params restored!");
err = mico_system_context_restore(sys_config);
require_noerr(err, exit);
@@ -136,8 +168,8 @@ int application_start(void) {
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac + 8);
}
tc1_log("user:%s", user_config->user);tc1_log("device name:%s",
sys_config->micoSystemConfig.name);tc1_log(
tc1_log("device name:%s",
sys_config->micoSystemConfig.name);tc1_log(
"mqtt_ip:%s", user_config->mqtt_ip);tc1_log("mqtt_port:%d",
user_config->mqtt_port);tc1_log(
"mqtt_user:%s", user_config->mqtt_user);
@@ -154,23 +186,24 @@ int application_start(void) {
}
}
KeyInit();
err = UserMqttInit();
require_noerr(err, exit);
err = UserRtcInit();
require_noerr(err, exit);
PowerInit();
AppHttpdStart(); // start http server thread
// udp_server_start();
//if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
// UserMqttInit();
// }
UserLedSet(user_config->power_led_enabled);
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
(mico_thread_function_t) schedule_p_count_task,
0x2000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the p_count thread.");
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
(mico_thread_function_t) reportMqttPowerInfoThread,
0x2000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
@@ -179,7 +212,6 @@ int application_start(void) {
if (user_config->task_top && now >= user_config->task_top->prs_time) {
ProcessTask();
}
mico_thread_msleep(1000);
}

View File

@@ -16,17 +16,17 @@
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
#define VERSION "v2.1.6"
#define VERSION "v2.2.0"
#define TYPE 1
#define TYPE_NAME "zTC1"
#define TYPE_NAME "TC1"
#define ZTC1_NAME "zTC1-%s"
#define ZTC1_NAME "TC1-%s"
#define USER_CONFIG_VERSION 8
#define USER_CONFIG_VERSION 9
#define SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。
#define SOCKET_NAME_LENGTH 32
#define SOCKET_NAME_LENGTH 64
#define SOCKET_NUM 6 //插座数量
#define Led MICO_GPIO_5
@@ -35,6 +35,7 @@
#define Relay_ON 1
#define Relay_OFF 0
#define Relay_TOGGLE -1
#define Relay_0 MICO_GPIO_6
#define Relay_1 MICO_GPIO_8
@@ -51,6 +52,7 @@ typedef struct
{
char version;
char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX];
char socket_names[SOCKET_NUM][SOCKET_NAME_LENGTH];
int mqtt_port;
int mqtt_report_freq;
char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX];
@@ -74,5 +76,7 @@ extern char str_mac[16];
extern system_config_t* sys_config;
extern user_config_t* user_config;
extern mico_gpio_t Relay[Relay_NUM];
extern int childLockEnabled;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@
#define MQTT_CMD_TIMEOUT 5000 // 5s
#define MQTT_YIELD_TMIE 5000 // 5s
#define MAX_MQTT_TOPIC_SIZE (256)
#define MAX_MQTT_DATA_SIZE (1024)
#define MAX_MQTT_TOPIC_SIZE (512)
#define MAX_MQTT_DATA_SIZE (2048)
#define MAX_MQTT_SEND_QUEUE_SIZE (10)
#define MQTT_SERVER user_config->mqtt_ip
@@ -21,7 +21,13 @@
#define MQTT_REPORT_FREQ user_config->mqtt_report_freq
#define MQTT_LED_ENABLED user_config->power_led_enabled
#define MQTT_SERVER_2 "183.156.82.30"
#define MQTT_SERVER_PORT_2 27834
#define MQTT_SERVER_USR_2 ""
#define MQTT_SERVER_PWD_2 ""
extern OSStatus UserMqttInit(void);
extern OSStatus UserMqttDeInit(void);
extern OSStatus UserMqttSend(char *arg);
@@ -29,10 +35,26 @@ extern bool UserMqttIsConnect(void);
extern OSStatus UserMqttSendSocketState(char socket_id);
extern OSStatus UserMqttSendLedState(void);
extern OSStatus UserMqttSendChildLockState(void);
extern OSStatus UserMqttSendTotalSocketState(void);
extern void UserMqttHassAuto(char socket_id);
extern void UserMqttHassPower(void);
extern void UserMqttHassAutoPower(void);
extern void UserMqttHassAutoLed(void);
extern void UserMqttHassAutoChildLock(void);
extern void UserMqttHassAutoTotalSocket(void);
extern void registerMqttEvents(void);
extern void UserMqttHassAutoRebootButton(void);
#endif

View File

@@ -257,7 +257,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
InitMd5(&md5);
}
httpHeader = HTTPHeaderCreateWithCallback(1024, OnReceivedData, NULL, NULL);
httpHeader = HTTPHeaderCreateWithCallback(512, OnReceivedData, NULL, NULL);
require_action(httpHeader, DELETE, OtaServerProgressSet(OTA_FAIL));
while (1)

View File

@@ -67,7 +67,7 @@ OSStatus UserRtcInit(void)
/* start rtc client */
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
(mico_thread_function_t) RtcThread,
0x1000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);

View File

@@ -6,8 +6,10 @@
#include"main.h"
#include"user_gpio.h"
#include "mqtt_server/user_mqtt_client.h"
#include"timed_task/timed_task.h"
#include"http_server/web_log.h"
#include "user_wifi.h"
int day_sec = 86400;
@@ -142,9 +144,61 @@ bool DelTask(int time)
void ProcessTask()
{
task_log("process task time[%ld] socket_idx[%d] on[%d]",
user_config->task_top->prs_time, user_config->task_top->socket_idx, user_config->task_top->on);
UserRelaySet(user_config->task_top->socket_idx, user_config->task_top->on);
task_log("process task time[%ld] operation[%s] on[%d]",
user_config->task_top->prs_time, get_func_name(user_config->task_top->operation), user_config->task_top->on);
switch (user_config->task_top->operation) {
case SWITCH_ALL_SOCKETS:
UserRelaySetAll(user_config->task_top->on);
mico_system_context_update(sys_config);
for (int i = 0; i < SOCKET_NUM; i++) {
UserMqttSendSocketState(i);
}
UserMqttSendTotalSocketState();
break;
case SWITCH_SOCKET_1:
case SWITCH_SOCKET_2:
case SWITCH_SOCKET_3:
case SWITCH_SOCKET_4:
case SWITCH_SOCKET_5:
case SWITCH_SOCKET_6:
UserRelaySet(user_config->task_top->operation - 1, user_config->task_top->on);
UserMqttSendSocketState(user_config->task_top->operation - 1);
UserMqttSendTotalSocketState();
mico_system_context_update(sys_config);
break;
case SWITCH_LED_ENABLE:
if (RelayOut() && user_config->task_top->on) {
UserLedSet(1);
} else {
UserLedSet(0);
}
UserMqttSendLedState();
mico_system_context_update(sys_config);
break;
case SWITCH_CHILD_LOCK_ENABLE:
user_config->user[0] = user_config->task_top->on;
childLockEnabled = user_config->user[0];
mico_system_context_update(sys_config);
UserMqttSendChildLockState();
break;
case REBOOT_SYSTEM:
MicoSystemReboot();
break;
case CONFIG_WIFI:
micoWlanSuspendStation();
ApInit(true);
break;
case RESET_SYSTEM:
mico_system_context_restore(sys_config);
mico_rtos_thread_sleep(1);
MicoSystemReboot();
break;
default:
break;
}
DelFirstTask();
}
@@ -164,8 +218,8 @@ char* GetTaskStr()
tm_info = localtime(&prs_time);
strftime(buffer, 26, "%m-%d %H:%M", tm_info);
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','socket_idx':%d,'on':%d,'weekday':%d},",
tmp_tsk->prs_time, buffer, tmp_tsk->socket_idx+1, tmp_tsk->on, tmp_tsk->weekday);
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','operation':%d,'on':%d,'weekday':%d},",
tmp_tsk->prs_time, buffer, tmp_tsk->operation, tmp_tsk->on, tmp_tsk->weekday);
tmp_str += strlen(tmp_str);
tmp_tsk = tmp_tsk->next;
}

View File

@@ -7,8 +7,8 @@ struct TimedTask
{
bool on_use; //正在使用
time_t prs_time; //被执行的格林尼治时间戳
int socket_idx; //要控制的插孔
int on; //开或者关
int operation; //要进行的操作
int on; //开或者关,或者其他操作
int weekday; //星期重复 0代表不重复 8代表每日重复
pTimedTask next; //下一个任务(按之间排序)
};

137
TC1/udp_server/udp_server.c Normal file
View File

@@ -0,0 +1,137 @@
#include "mico.h"
#include "SocketUtils.h"
#include "json_c/json.h"
#include "mqtt_server/user_mqtt_client.h"
#include "user_power.h"
#include "main.h"
#include "user_gpio.h"
#include "user_wifi.h"
#include "http_server/app_httpd.h"
#define UDP_SERVER_IP "192.168.31.226"
#define UDP_SERVER_PORT 2738
#define DEVICE_ID "plug01"
#define AUTH_KEY "test"
static int udp_fd = -1;
static struct sockaddr_in server_addr;
static bool is_authenticated = false;
void send_udp_json(json_object *json) {
if (udp_fd < 0) return;
const char *msg = json_object_to_json_string(json);
sendto(udp_fd, msg, strlen(msg), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
}
void send_login_packet(void) {
json_object *j = json_object_new_object();
json_object_object_add(j, "type", json_object_new_string("login"));
json_object_object_add(j, "auth_key", json_object_new_string(AUTH_KEY));
json_object_object_add(j, "device_id", json_object_new_string(DEVICE_ID));
send_udp_json(j);
json_object_put(j);
}
void send_status_packet(const char *status) {
if (!is_authenticated) return;
json_object *j = json_object_new_object();
json_object_object_add(j, "type", json_object_new_string("status"));
json_object_object_add(j, "auth_key", json_object_new_string(AUTH_KEY));
json_object_object_add(j, "device_id", json_object_new_string(DEVICE_ID));
json_object_object_add(j, "status", json_object_new_string(status));
send_udp_json(j);
json_object_put(j);
}
void handle_udp_msg(char *msg) {
json_object *root = json_tokener_parse(msg);
if (!root) return;
const char *type = json_object_get_string(json_object_object_get(root, "type"));
if (strcmp(type, "login_ack") == 0) {
const char *result = json_object_get_string(json_object_object_get(root, "result"));
if (strcmp(result, "ok") == 0) {
is_authenticated = true;
}
} else if (strcmp(type, "control") == 0 && is_authenticated) {
const char *cmd = json_object_get_string(json_object_object_get(root, "command"));
// TODO: 控制插座硬件
if (strcmp(cmd, "turn_on") == 0) {
// gpio_output_high(PLUG_PIN);
} else if (strcmp(cmd, "turn_off") == 0) {
// gpio_output_low(PLUG_PIN);
}
}
json_object_put(root);
}
void udp_recv_loop(void) {
char buf[256];
while (1) {
if (udp_fd >= 0) {
int len = recvfrom(udp_fd, buf, sizeof(buf) - 1, 0, NULL, 0);
if (len > 0) {
buf[len] = '\0';
handle_udp_msg(buf);
}
}
mico_thread_sleep(1);
}
}
void udp_heartbeat_loop(void) {
while (1) {
if (udp_fd < 0) {
udp_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (udp_fd < 0) {
mico_thread_sleep(3);
continue;
}
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(UDP_SERVER_PORT);
server_addr.sin_addr.s_addr = inet_addr(UDP_SERVER_IP);
}
if (!is_authenticated) {
send_login_packet();
} else {
char *sockets = GetSocketStatus();
char *short_click_config = GetButtonClickConfig();
char *tc1_status = malloc(1500);
char *socket_names = malloc(512);
sprintf(socket_names, "%s,%s,%s,%s,%s,%s",
user_config->socket_names[0],
user_config->socket_names[1],
user_config->socket_names[2],
user_config->socket_names[3],
user_config->socket_names[4],
user_config->socket_names[5]);
sprintf(tc1_status, TC1_STATUS_JSON, sockets, ip_status.mode,
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT,
MQTT_SERVER_USR, MQTT_SERVER_PWD,
VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, user_config->mqtt_report_freq,
user_config->power_led_enabled, 0L, socket_names, childLockEnabled,
sys_config->micoSystemConfig.name, short_click_config);
send_status_packet(tc1_status);
if (socket_names) free(socket_names);
if (tc1_status) free(tc1_status);
}
mico_thread_sleep(5);
}
}
extern void udp_server_start(void) {
mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "udp_recv", udp_recv_loop, 0x800, NULL);
mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "udp_send", udp_heartbeat_loop, 0x800, NULL);
}

View File

@@ -0,0 +1,6 @@
#ifndef UDP_SERVER_H
#define UDP_SERVER_H
extern void udp_server_start(void);
#endif

View File

@@ -2,13 +2,14 @@
#include "main.h"
#include "user_gpio.h"
#include "user_wifi.h"
#include "mqtt_server/user_mqtt_client.h"
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
char socket_status[32] = { 0 };
mico_gpio_t relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
char socket_status[32] = {0};
char btn_click_config[500] = {0};
void UserLedSet(char x)
{
void UserLedSet(char x) {
if (x == -1)
MicoGpioOutputTrigger(Led);
else if (x)
@@ -17,75 +18,142 @@ void UserLedSet(char x)
MicoGpioOutputLow(Led);
}
bool RelayOut(void)
{
bool RelayOut(void) {
int i;
for (i = 0; i < SOCKET_NUM; i++)
{
if (user_config->socket_status[i] != 0)
{
for (i = 0; i < SOCKET_NUM; i++) {
if (user_config->socket_status[i] != 0) {
return true;
}
}
return false;
}
char* GetSocketStatus()
{
char* get_func_name(char func_code) {
static char buffer[32];
switch (func_code) {
case SWITCH_ALL_SOCKETS:
return "Toggle All Sockets";
case SWITCH_SOCKET_1:
case SWITCH_SOCKET_2:
case SWITCH_SOCKET_3:
case SWITCH_SOCKET_4:
case SWITCH_SOCKET_5:
case SWITCH_SOCKET_6:
sprintf(buffer, "Toggle Socket %d %s", func_code - 1,
user_config->socket_names[func_code - 1]);
return buffer;
case SWITCH_LED_ENABLE:
return "Toggle LED";
case REBOOT_SYSTEM:
return "Reboot";
case REBOOT_HTTP:
return "REBOOT_HTTP";
case CONFIG_WIFI:
return "WiFi Config";
case RESET_SYSTEM:
return "Factory Reset";
case SWITCH_CHILD_LOCK_ENABLE:
return "Toggle ChildLick";
case -1:
case NO_FUNCTION:
return "Unassigned";
default:
return "Unknown";
}
}
/// 针对电源按钮的点击事件
/// \param index 判断短按(连击)时,代表连击次数,判断长按时代表长按秒数
/// \param short_func 功能码 在user_gpio.h中定义了
/// \param long_func 功能码 在user_gpio.h中定义了
void set_key_map(char user[],int index, char short_func, char long_func) {
user[index] = ((long_func & 0x0F) << 4) | (short_func & 0x0F);
}
char get_short_func(char val) {
char func = val & 0x0F;
return (func == NO_FUNCTION) ? -1 : func; // -1 表示未配置
}
char get_long_func(char val) {
char func = (val >> 4) & 0x0F;
return (func == NO_FUNCTION) ? -1 : func; // -1 表示未配置
}
char *GetSocketStatus() {
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
user_config->socket_status[0],
user_config->socket_status[1],
user_config->socket_status[2],
user_config->socket_status[3],
user_config->socket_status[4],
user_config->socket_status[5]);
user_config->socket_status[0],
user_config->socket_status[1],
user_config->socket_status[2],
user_config->socket_status[3],
user_config->socket_status[4],
user_config->socket_status[5]);
return socket_status;
}
void SetSocketStatus(char* socket_status)
{
char *GetButtonClickConfig() {
char temp[32];
int len = 0;
int max_len =sizeof(btn_click_config);
len += snprintf(btn_click_config + len, max_len - len, "[");
for (int i = 1; i <= 30; i++) {
char short_func = get_short_func(user_config->user[i]);
char long_func = get_long_func(user_config->user[i]);
// key_log("WARNGIN:KEY func %d %d %d", i,short_func,long_func);
snprintf(temp, sizeof(temp), "{'%d':[%d,%d]}%s", i, short_func, long_func, (i != 30) ? "," : "");
len += snprintf(btn_click_config + len, max_len - len, "%s", temp);
if (len >= max_len - 1) break;
}
snprintf(btn_click_config + len, max_len - len, "]");
return btn_click_config;
}
void SetSocketStatus(char *socket_status) {
sscanf(socket_status, "%d,%d,%d,%d,%d,%d,",
(int*)&user_config->socket_status[0],
(int*)&user_config->socket_status[1],
(int*)&user_config->socket_status[2],
(int*)&user_config->socket_status[3],
(int*)&user_config->socket_status[4],
(int*)&user_config->socket_status[5]);
(int *) &user_config->socket_status[0],
(int *) &user_config->socket_status[1],
(int *) &user_config->socket_status[2],
(int *) &user_config->socket_status[3],
(int *) &user_config->socket_status[4],
(int *) &user_config->socket_status[5]);
int i = 0;
for (i = 0; i < SOCKET_NUM; i++)
{
for (i = 0; i < SOCKET_NUM; i++) {
UserRelaySet(i, user_config->socket_status[i]);
UserMqttSendSocketState(i);
}
UserMqttSendTotalSocketState();
mico_system_context_update(sys_config);
}
/*UserRelaySet
* 设置继电器开关
* i:编号 0-5
* on:开关 0:关 1:开
* on:开关 0:关 1:开 -1:切换
*/
void UserRelaySet(unsigned char i, unsigned char on)
{
void UserRelaySet(unsigned char i, char on) {
if (i < 0 || i >= SOCKET_NUM) return;
if (on == Relay_ON)
{
if (on == Relay_ON) {
MicoGpioOutputHigh(relay[i]);
}
else
{
} else if (on == Relay_OFF) {
MicoGpioOutputLow(relay[i]);
} else if (on == Relay_TOGGLE) {
if (user_config->socket_status[i] == Relay_OFF) {
MicoGpioOutputHigh(relay[i]);
} else {
MicoGpioOutputLow(relay[i]);
}
}
user_config->socket_status[i] = on >= 0 ? on : (user_config->socket_status[i] == 0 ? 1 : 0);
user_config->socket_status[i] = on;
if (RelayOut()&&user_config->power_led_enabled)
{
if (RelayOut() && user_config->power_led_enabled) {
UserLedSet(1);
}
else
{
} else {
UserLedSet(0);
}
}
@@ -95,111 +163,229 @@ void UserRelaySet(unsigned char i, unsigned char on)
* y: 0:全部关 1:全部开
*
*/
void UserRelaySetAll(char y)
{
void UserRelaySetAll(char y) {
int i;
for (i = 0; i < SOCKET_NUM; i++)
UserRelaySet(i, y);
}
static void KeyLongPress(void)
{
// key_log("KeyLongPress");
// UserLedSet(1);
// UserMqttSend("mqtt test");
static void KeyEventHandler(int num, boolean longPress) {
key_log("WARNGIN:Power key %s %d %s", !longPress ? "quick clicked" : "longPressed", num,
num > 1 ? (longPress ? "seconds" : "times") : (longPress ? "second" : "time"));
if (num > 30 || num <= 0)
return;
int function = !longPress ? get_short_func(user_config->user[num]) : get_long_func(
user_config->user[num]);
boolean showLog= childLockEnabled==0;
switch (function) {
case SWITCH_ALL_SOCKETS:
if (childLockEnabled)
break;
if (RelayOut()) {
UserRelaySetAll(0);
} else {
UserRelaySetAll(1);
}
mico_system_context_update(sys_config);
for (int i = 0; i < SOCKET_NUM; i++) {
UserMqttSendSocketState(i);
}
UserMqttSendTotalSocketState();
break;
case SWITCH_SOCKET_1:
case SWITCH_SOCKET_2:
case SWITCH_SOCKET_3:
case SWITCH_SOCKET_4:
case SWITCH_SOCKET_5:
case SWITCH_SOCKET_6:
if (childLockEnabled)
break;
UserRelaySet(function - 1, Relay_TOGGLE);
UserMqttSendSocketState(function - 1);
UserMqttSendTotalSocketState();
mico_system_context_update(sys_config);
break;
case SWITCH_LED_ENABLE:
if (childLockEnabled)
break;
MQTT_LED_ENABLED = MQTT_LED_ENABLED == 0 ? 1 : 0;
if (RelayOut() && MQTT_LED_ENABLED) {
UserLedSet(1);
} else {
UserLedSet(0);
}
UserMqttSendLedState();
mico_system_context_update(sys_config);
break;
case SWITCH_CHILD_LOCK_ENABLE:
showLog=true;
user_config->user[0] = user_config->user[0] == 0 ? 1 : 0;
childLockEnabled = user_config->user[0];
mico_system_context_update(sys_config);
UserMqttSendChildLockState();
break;
case REBOOT_SYSTEM:
if (childLockEnabled)
break;
MicoSystemReboot();
break;
case REBOOT_HTTP:
if (childLockEnabled)
break;
AppHttpdStop();
mico_rtos_thread_sleep(1);
AppHttpdStart();
break;
case CONFIG_WIFI:
if (childLockEnabled)
break;
StartLedBlink(3);
UserMqttDeInit();
micoWlanSuspendStation();
ApInit(true);
break;
case RESET_SYSTEM:
if (childLockEnabled)
break;
StartLedBlink(8);
mico_system_context_restore(sys_config);
mico_rtos_thread_sleep(1);
MicoSystemReboot();
break;
default:
break;
}
key_log("WARNGIN:%s",showLog? get_func_name(function):"child lock enabled,ignore key event !");
}
static void KeyLong10sPress(void)
{
key_log("WARNGIN: user params restored!");
appRestoreDefault_callback(user_config, sizeof(user_config_t));
sys_config->micoSystemConfig.ssid[0] = 0;
mico_system_context_update(mico_system_context_get());
}
static void KeyShortPress(void)
{
char i;
if (RelayOut())
{
UserRelaySetAll(0);
}
else
{
UserRelaySetAll(1);
}
for (i = 0; i < SOCKET_NUM; i++)
{
UserMqttSendSocketState(i);
}
}
mico_timer_t user_key_timer;
// 全局静态变量声明
static uint8_t click_count = 0;
static mico_timer_t click_end_timer;
uint16_t key_time = 0;
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
static void KeyTimeoutHandler(void* arg)
static mico_timer_t led_blink_timer;
static bool timer_initialized = false;
static uint8_t total_blinks = 0;
static uint8_t blink_counter = 0;
static bool led_state = false;
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
// 定时器回调
static void _led_blink_timer_handler(void *arg)
{
if (blink_counter >= total_blinks) {
UserLedSet(0); // 闪烁完成,灭灯
mico_stop_timer(&led_blink_timer);
mico_deinit_timer(&led_blink_timer);
timer_initialized = false;
return;
}
led_state = !led_state;
UserLedSet(led_state ? 1 : 0);
blink_counter++;
}
// 安全重入的启动函数
void StartLedBlink(uint8_t times)
{
if (times == 0) return;
// 如果之前已启动,先停止并清理
if (timer_initialized) {
mico_stop_timer(&led_blink_timer);
mico_deinit_timer(&led_blink_timer);
timer_initialized = false;
}
total_blinks = times * 2;
blink_counter = 0;
led_state = false;
mico_init_timer(&led_blink_timer, 100, _led_blink_timer_handler, NULL);
mico_start_timer(&led_blink_timer);
timer_initialized = true;
}
static void ClickEndTimeoutHandler(void *arg) {
if (click_count <= 0) {
click_count = 0;
return;
}
KeyEventHandler(click_count,false);
click_count = 0;
}
static void KeyTimeoutHandler(void *arg) {
static char key_trigger, key_continue;
//按键扫描程序
static uint8_t key_time = 0;
char tmp = ~(0xfe | MicoGpioInputGet(Button));
key_trigger = tmp & (tmp ^ key_continue);
key_continue = tmp;
if (key_trigger != 0) key_time = 0; //新按键按下时,重新开始按键计时
if (key_continue != 0)
{
//any button pressed
key_time++;
if (key_time <= BUTTON_LONG_PRESS_TIME)
{
key_log("button long pressed:%d",key_time);
if (key_time == 30)
{
KeyLongPress();
}
else if (key_time == 100)
{
KeyLong10sPress();
}
else if (key_time == 102)
{
UserLedSet(1);
}
else if (key_time == 103)
{
UserLedSet(0);
key_time = 101;
}
}
}
else
{
//button released
if (key_time < BUTTON_LONG_PRESS_TIME)
{ //100ms*10=1s 大于1s为长按
key_time = 0;
key_log("button short pressed:%d",key_time);
KeyShortPress();
}
else if (key_time > 100)
{
MicoSystemReboot();
if (key_trigger != 0)
key_time = 0;
if (key_continue != 0) {
key_time++;
// if (key_time > BUTTON_LONG_PRESS_TIME) {
// if (key_time == 50) {
// KeyLong5sPress();
// } else if (key_time > 50 && key_time < 57) {
// switch (key_time) {
// case 51:
// UserLedSet(1);
// break;
// case 52:
// UserLedSet(0);
// break;
// case 53:
// UserLedSet(1);
// break;
// case 54:
// UserLedSet(0);
// break;
// case 55:
// UserLedSet(1);
// break;
// case 56:
// UserLedSet(0);
// break;
// }
// } else if (key_time == 57) {
// UserLedSet(RelayOut() && user_config->power_led_enabled);
// } else if (key_time == 100) {
// KeyLong10sPress();
// } else if (key_time == 102) {
// UserLedSet(1);
// } else if (key_time == 103) {
// UserLedSet(0);
// key_time = 101;
// }
// }
} else {
if (key_time < BUTTON_LONG_PRESS_TIME) {
click_count++;
// 重启 click_end_timer300ms
mico_rtos_stop_timer(&click_end_timer);
mico_rtos_start_timer(&click_end_timer);
} else {
KeyEventHandler(key_time/10,true);
}
mico_rtos_stop_timer(&user_key_timer);
}
}
static void KeyFallingIrqHandler(void* arg)
{
static void KeyFallingIrqHandler(void *arg) {
mico_rtos_start_timer(&user_key_timer);
}
void KeyInit(void)
{
void KeyInit(void) {
MicoGpioInitialize(Button, INPUT_PULL_UP);
mico_rtos_init_timer(&user_key_timer, 100, KeyTimeoutHandler, NULL);
mico_rtos_init_timer(&click_end_timer, 400, ClickEndTimeoutHandler, NULL);
MicoGpioEnableIRQ(Button, IRQ_TRIGGER_FALLING_EDGE, KeyFallingIrqHandler, NULL);
}

View File

@@ -4,14 +4,35 @@
#include "mico.h"
#include "micokit_ext.h"
#define NO_FUNCTION 0x0F
#define SWITCH_ALL_SOCKETS 0
#define SWITCH_SOCKET_1 1
#define SWITCH_SOCKET_2 2
#define SWITCH_SOCKET_3 3
#define SWITCH_SOCKET_4 4
#define SWITCH_SOCKET_5 5
#define SWITCH_SOCKET_6 6
#define SWITCH_LED_ENABLE 7
#define REBOOT_SYSTEM 8
#define CONFIG_WIFI 9
#define RESET_SYSTEM 10
#define SWITCH_CHILD_LOCK_ENABLE 11
#define REBOOT_HTTP 12
extern char socket_status[32];
void UserLedSet(char x);
void KeyInit(void);
void UserRelaySet(unsigned char x,unsigned char y);
void UserRelaySet(unsigned char x, char y);
void UserRelaySetAll(char y);
bool RelayOut(void);
char* GetSocketStatus();
char* GetButtonClickConfig();
void SetSocketStatus(char* socket_status);
void set_key_map(char user[],int index, char short_func, char long_func);
char get_short_func(char val);
char get_long_func(char val);
char *get_func_name(char func_code);
void StartLedBlink(uint8_t times);
#endif

View File

@@ -7,26 +7,23 @@
#include "user_power.h"
uint32_t p_count = 0;
PowerRecord power_record = { 1,{ 0 } };
char power_record_str[1101] = { 0 };
PowerRecord power_record = {1, {0}};
char power_record_str[1101] = {0};
float real_time_power = 0;
void SetPowerRecord(PowerRecord* pr, uint32_t pw)
{
pr->powers[(++pr->idx)% PW_NUM] = pw;
void SetPowerRecord(PowerRecord *pr, uint32_t pw) {
pr->powers[(++pr->idx) % PW_NUM] = pw;
}
char* GetPowerRecord(int idx)
{
char *GetPowerRecord(int idx) {
if (idx > power_record.idx) return "";
idx = idx <= power_record.idx - PW_NUM ? 0 : idx;
int i = idx > 0 ? idx : (power_record.idx - PW_NUM + 1);
i = i < 0 ? 0 : i;
char* tmp = power_record_str;
for (; i <= power_record.idx; i++)
{
sprintf(tmp, "%lu,", power_record.powers[i%PW_NUM]);
char *tmp = power_record_str;
for (; i <= power_record.idx; i++) {
sprintf(tmp, "%lu,", power_record.powers[i % PW_NUM]);
tmp += strlen(tmp);
}
*(--tmp) = 0;
@@ -38,9 +35,11 @@ float n_1s = 0; //在当前这一秒功率中断次数
uint64_t past_ns = 0; //系统运行的纳秒数
uint64_t irq_old = 0; //上次中断的时间(纳秒)
static void PowerIrqHandler(void* arg)
{
static void PowerIrqHandler(void *arg) {
//警告! 不能在此函数里调用任何有关moloc()的操作
if (p_count == 0) {
p_count = user_config->p_count_1_day_ago;
}
p_count++;
@@ -48,30 +47,27 @@ static void PowerIrqHandler(void* arg)
past_ns = mico_nanosecond_clock_value(); //系统运行纳秒数
uint64_t spend_ns = past_ns - irq_old;
if (irq_old % NS + spend_ns <= NS)
{
if (irq_old % NS + spend_ns <= NS) {
n_1s += 1;
irq_old = past_ns;
return;
}
int n = (spend_ns - past_ns % NS) / NS;
n_1s += (float)(NS - irq_old % NS) / spend_ns;
n_1s += (float) (NS - irq_old % NS) / spend_ns;
real_time_power = 17.1 * n_1s;
SetPowerRecord(&power_record, (int)real_time_power);
SetPowerRecord(&power_record, (int) real_time_power);
int i = 0;
for (; i < n; i++)
{
for (; i < n; i++) {
real_time_power = 17.1 * NS / spend_ns;
SetPowerRecord(&power_record, (int)real_time_power);
SetPowerRecord(&power_record, (int) real_time_power);
}
irq_old = past_ns;
n_1s = (float)(past_ns % NS) / spend_ns;
n_1s = (float) (past_ns % NS) / spend_ns;
}
void PowerInit(void)
{
void PowerInit(void) {
power_log("PowerInit");
MicoGpioInitialize(POWER, INPUT_PULL_UP);
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);

View File

@@ -4,6 +4,7 @@
#include "mico_socket.h"
#include "user_gpio.h"
#include "http_server/web_log.h"
#include "mqtt_server/user_mqtt_client.h"
char wifi_status = WIFI_STATE_NOCONNECT;
@@ -122,6 +123,11 @@ static void WifiLedTimerCallback(void* arg)
UserLedSet(-1);
break;
case WIFI_STATE_CONNECTED:
wifi_log("wifi connected!!");
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
UserMqttInit();
}
UserLedSet(0);
mico_rtos_stop_timer(&wifi_led_timer);
if (RelayOut()&&user_config->power_led_enabled)

View File

@@ -1,11 +1,27 @@
cd ./TC1/http_server
python ./test.py > web_data.c
cd ../..
mico make clean
mico make TC1@MK3031@moc total
cp ./build/TC1\@MK3031\@moc/binary/TC1\@MK3031\@moc.ota.bin ./build/TC1\@MK3031\@moc/binary/ota.bin
version_file=".version"
if [ ! -f $version_file ]; then echo "v1.0.0" > $version_file; fi
# 读当前版本并自增
ver=$(cat $version_file)
major=$(echo $ver | cut -d. -f1 | sed 's/v//')
minor=$(echo $ver | cut -d. -f2)
patch=$(echo $ver | cut -d. -f3)
patch=$((patch + 1))
new_ver="v${major}.${minor}.${patch}"
echo $new_ver > $version_file
cd ./TC1/http_server
python ./test.py > web_data.c
cd ../..
mico make TC1@MK3031@moc total
cp ./build/TC1\@MK3031\@moc/binary/TC1\@MK3031\@moc.ota.bin ./build/TC1\@MK3031\@moc/binary/ota.bin
cp ./build/TC1\@MK3031\@moc/binary/TC1\@MK3031\@moc.ota.bin ./build/TC1\@MK3031\@moc/binary/ota$(date +%Y%m%d%H%M%S).bin
cp ./build/TC1\@MK3031\@moc/binary/TC1\@MK3031\@moc.all.bin ./build/TC1\@MK3031\@moc/binary/all$(date +%Y%m%d%H%M%S).bin

BIN
doc/IMG_0862.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 KiB

BIN
doc/IMG_0863.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

BIN
doc/IMG_0887.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

BIN
doc/IMG_0888.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 KiB

0
git版本.txt Normal file
View File

4
mico-os/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
MiCoder/compiler
Projects
MiCoder
tools_root

View File

@@ -39,17 +39,11 @@ OSStatus system_discovery_init( system_context_t * const inContext )
init.service_name = "_easylink._tcp.local.";
/* name#xxxxxx.local. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
snprintf( temp_txt, 100, "%s.local.", inContext->flashContentInRam.micoSystemConfig.name);
init.host_name = (char*)__strdup(temp_txt);
/* name#xxxxxx. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
snprintf( temp_txt, 100, "%s", inContext->flashContentInRam.micoSystemConfig.name);
init.instance_name = (char*)__strdup(temp_txt);
#ifndef MICO_LOCAL_SERVER_PORT

View File

@@ -50,7 +50,8 @@ httpd_state_t httpd_state;
static mico_thread_t httpd_main_thread;
#define http_server_thread_stack_size 0x2000
// 0x8000 不行
#define http_server_thread_stack_size 0x5000
/* Why HTTPD_MAX_MESSAGE + 2?
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.

View File

@@ -1125,6 +1125,8 @@ int httpd_parse_hdr_tags(httpd_request_t *req, int sock,
*/
int httpd_get_data(httpd_request_t *req, char *content, int length);
int httpd_get_data2(httpd_request_t *req, char *content, int length);
/** @brief Get the incoming JSON data in case of HTTP POST request
*
* @note This function is an extension to \ref httpd_get_data. Additionally this

View File

@@ -543,6 +543,52 @@ out:
return req->remaining_bytes;
}
int httpd_get_data2(httpd_request_t *req, char *content, int length)
{
int ret;
char *buf;
// /* Is this condition required? */
// if (req->body_nbytes >= HTTPD_MAX_MESSAGE - 2)
// return -kInProgressErr;
if (!req->hdr_parsed) {
buf = malloc(HTTPD_MAX_MESSAGE);
if (!buf) {
system_log("Failed to allocate memory for buffer");
return -kInProgressErr;
}
ret = httpd_parse_hdr_tags(req, req->sock, buf,
HTTPD_MAX_MESSAGE);
if (ret != kNoErr) {
system_log("Unable to parse header tags");
goto out;
} else {
system_log("Headers parsed successfully\r\n");
req->hdr_parsed = 1;
}
free(buf);
}
/* handle here */
ret = httpd_recv(req->sock, content,
length, 0);
if (ret == -1) {
system_log("Failed to read POST data");
goto out;
}
/* scratch will now have the JSON data */
// content[ret] = '\0';
req->remaining_bytes -= ret;
system_log("Read %d bytes and remaining %d bytes",
ret, req->remaining_bytes);
out:
return ret;
}
static int get_matching_chars(const char *s1, const char *s2)
{
int match = 0;