mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-05-12 03:04:45 +08:00
Compare commits
142 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8496e8cfd6 | ||
|
|
ade64139cb | ||
|
|
eaf8f5bf60 | ||
|
|
5eecfefc74 | ||
|
|
0c675c6f03 | ||
|
|
982e82c2bb | ||
|
|
eece61e380 | ||
|
|
36861fadff | ||
|
|
f3b7477550 | ||
|
|
dfa8b1c475 | ||
|
|
c7d2f8d7d0 | ||
|
|
e352b74e19 | ||
|
|
3f5078294f | ||
|
|
d7e2243a86 | ||
|
|
4e1b376b6a | ||
|
|
393af288ec | ||
|
|
e9f1448a69 | ||
|
|
004eaf28dd | ||
|
|
0e361111a5 | ||
|
|
026e058934 | ||
|
|
5623b632c7 | ||
|
|
34e1cabc53 | ||
|
|
55a5f93148 | ||
|
|
86b78d8a4e | ||
|
|
d8099ad499 | ||
|
|
4aca161327 | ||
|
|
67aa42fdd9 | ||
|
|
6e3a48cba6 | ||
|
|
fea21ab02a | ||
|
|
49847dc77c | ||
|
|
e6d430c37c | ||
|
|
7c77be5455 | ||
|
|
6598250af1 | ||
|
|
60977f0327 | ||
|
|
f1ba19554e | ||
|
|
2b1577998c | ||
|
|
a5c9211fb6 | ||
|
|
e735afc6c5 | ||
|
|
f8d2b25d1e | ||
|
|
a342d4552a | ||
|
|
759a5ec5cc | ||
|
|
0ba50e9a52 | ||
|
|
f8fba89793 | ||
|
|
30a353c035 | ||
|
|
b470b0f8a0 | ||
|
|
76e8612007 | ||
|
|
6cf213a1b9 | ||
|
|
c214f0de30 | ||
|
|
bf7c8dd7fe | ||
|
|
b2bd368b2d | ||
|
|
56c9923336 | ||
|
|
2d34767cde | ||
|
|
2258158a0d | ||
|
|
f7b6b8ae0a | ||
|
|
b38f9f91d8 | ||
|
|
84cf4bfc06 | ||
|
|
542e5daf8a | ||
|
|
ceb208813a | ||
|
|
fe4d037390 | ||
|
|
8e083fe175 | ||
|
|
9ac9e5e2f1 | ||
|
|
36d8330ee3 | ||
|
|
a51c7a8eb2 | ||
|
|
6ef875879f | ||
|
|
2b2a77b5f5 | ||
|
|
787e57439e | ||
|
|
fd157172e3 | ||
|
|
989fd0a1ed | ||
|
|
a76afc6ccb | ||
|
|
23fcd56109 | ||
|
|
a6bb74f906 | ||
|
|
fd5d190096 | ||
|
|
997eda3ef2 | ||
|
|
e4e0ca969e | ||
|
|
4ea9df172b | ||
|
|
d0a71fe216 | ||
|
|
c8dd3d513d | ||
|
|
dd5b282c85 | ||
|
|
8acef18406 | ||
|
|
13df06e546 | ||
|
|
9df4b8358b | ||
|
|
bdfed87f1e | ||
|
|
7ea87ae4c9 | ||
|
|
a87d894c4d | ||
|
|
d7e695e37e | ||
|
|
40bdb50a8d | ||
|
|
caffddfb43 | ||
|
|
11d3d50265 | ||
|
|
66d2863fa4 | ||
|
|
56395f62bc | ||
|
|
0d5ba4a7d3 | ||
|
|
d925c7d805 | ||
|
|
b40bb1a022 | ||
|
|
981c33e3ad | ||
|
|
fc631ac9f5 | ||
|
|
840b0eb374 | ||
|
|
f2f63625cc | ||
|
|
78dbc6209b | ||
|
|
2896243e24 | ||
|
|
9d80970e9e | ||
|
|
7bac9096f5 | ||
|
|
5f81f2ca71 | ||
|
|
57dbe17175 | ||
|
|
a8d5319d52 | ||
|
|
f41a20f8d0 | ||
|
|
52da5983b5 | ||
|
|
758abf123b | ||
|
|
e3de06437b | ||
|
|
7f0e5d15c8 | ||
|
|
7656ae998c | ||
|
|
3aec445e57 | ||
|
|
7048333ebc | ||
|
|
bfae22ddd6 | ||
|
|
520a245ef3 | ||
|
|
1f92b30ea0 | ||
|
|
4a20713693 | ||
|
|
b36fce48f5 | ||
|
|
1b7d86f1f7 | ||
|
|
d7c83fa125 | ||
|
|
44ed1d2604 | ||
|
|
f17ca68404 | ||
|
|
b5cb7b8218 | ||
|
|
b099618b91 | ||
|
|
160f4f5b7f | ||
|
|
168f89cc82 | ||
|
|
713dd1a907 | ||
|
|
8537240bbd | ||
|
|
5a1b82b728 | ||
|
|
9caeec8611 | ||
|
|
8a28029940 | ||
|
|
3964703152 | ||
|
|
4b000d109c | ||
|
|
90ba74b401 | ||
|
|
208a7b3ef9 | ||
|
|
ba943fe6ae | ||
|
|
3fca5b51aa | ||
|
|
daa3415717 | ||
|
|
e7d380bf4c | ||
|
|
eb7241e235 | ||
|
|
3350aa5446 | ||
|
|
c94e8fcd12 | ||
|
|
4ed9dbd435 |
125
.cproject
Normal file
125
.cproject
Normal 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
2
.gdbinit
Normal 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
3
.openocd_cfg
Normal 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
27
.project
Normal 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>
|
||||||
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal 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
24
.vscode/launch.json
vendored
Normal 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
59
.vscode/settings.json
vendored
Normal 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
|
||||||
|
}
|
||||||
21
README.md
21
README.md
@@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
# 固件web界面
|
# 固件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接入效果
|
# HASS接入效果
|
||||||
<img src="doc/3.png">
|
<img src="doc/IMG_0888.png">
|
||||||
|
|
||||||
固件启动后, 会开启一个热点 TC1-AP-XXXXXX,连接热点后, 直接用浏览器访问: http://192.168.0.1 即可看到如上web界面.
|
固件启动后, 会开启一个热点 TC1-AP-XXXXXX,连接热点后, 直接用浏览器访问: http://192.168.0.1 即可看到如上web界面.
|
||||||
|
|
||||||
@@ -53,7 +53,16 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
|||||||
- [x] HomeAssistant中增加总耗电量传感器,今日耗电量传感器,昨日耗电量传感器,数据来自于插座历史统计
|
- [x] HomeAssistant中增加总耗电量传感器,今日耗电量传感器,昨日耗电量传感器,数据来自于插座历史统计
|
||||||
- [x] 可以设置mqtt数据上报频率,默认2秒
|
- [x] 可以设置mqtt数据上报频率,默认2秒
|
||||||
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
|
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
|
||||||
|
- [x] 后台和ha mqtt增加总开关控制
|
||||||
|
- [x] 后台可以自定义6个插座的名称,名称将会自动同步到ha mqtt
|
||||||
|
- [x] 修复了原代码中电源按钮长按 (现在是5秒)重新配网和(10秒)恢复出厂的逻辑错误
|
||||||
|
- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,**上电时同时按住按钮的话会开启配网热点**(防止开了童锁,wifi又嗝屁,导致插座功能暴毙的救命逻辑)
|
||||||
|
- [x] 后台可自定义设备名称,此名称将会同至ha mqtt作为mqtt中插座名称的前缀
|
||||||
|
- [x] 后台可自定义按键连击,长按等功能
|
||||||
|
- [x] 定时开关现在支持更多操作项,与按键功能自定义一样
|
||||||
|
- [x] 现在可以上传本地文件来更新固件,同时可以在最新发布的固件说明中参考使用我搭建的文件服务来在线更新
|
||||||
|
# 固件烧录
|
||||||
|
- 参考原始固件代码提供者[a2633063](https://github.com/a2633063/zTC1/wiki/固件烧录)大佬提供的说明
|
||||||
# 编译固件
|
# 编译固件
|
||||||
|
|
||||||
- windows环境,先安装python2.7,下载安装的时候添加环境变量到Path,默认安装路径需要添加两个环境变量C:\Python27;C:\Python27\Scripts
|
- windows环境,先安装python2.7,下载安装的时候添加环境变量到Path,默认安装路径需要添加两个环境变量C:\Python27;C:\Python27\Scripts
|
||||||
@@ -62,8 +71,10 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
|||||||
- 安装完成后添加micoder路径 mico config --global MICODER (micoder所在路径)/MiCoder
|
- 安装完成后添加micoder路径 mico config --global MICODER (micoder所在路径)/MiCoder
|
||||||
- 最后切换到此项目根目录执行build.sh即可编译固件
|
- 最后切换到此项目根目录执行build.sh即可编译固件
|
||||||
|
|
||||||
|
# 注意事项
|
||||||
|
- 使用pip安装mico-cube失败,请使用下列命令安装(执行命令时注意路径位置)
|
||||||
|
|
||||||
|
- `python -m pip install mico-cube-1.0.0.tar.gz`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,11 @@
|
|||||||
#include <http-strings.h>
|
#include <http-strings.h>
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "httpd_priv.h"
|
#include "httpd_priv.h"
|
||||||
#include "app_httpd.h"
|
#include "app_httpd.h"
|
||||||
@@ -52,8 +57,11 @@
|
|||||||
static bool is_http_init;
|
static bool is_http_init;
|
||||||
static bool is_handlers_registered;
|
static bool is_handlers_registered;
|
||||||
const struct httpd_wsgi_call g_app_handlers[];
|
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";
|
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)
|
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;
|
OSStatus err = kNoErr;
|
||||||
|
for (int offset = 0; offset < total_len; offset += CHUNK_SIZE) {
|
||||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
|
int chunk_len = (total_len - offset > CHUNK_SIZE) ? CHUNK_SIZE : (total_len - offset);
|
||||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index headers."));
|
err = httpd_send_body(sock, data + offset, chunk_len);
|
||||||
|
require_noerr_action(err, exit, http_log("ERROR: Send chunk failed at offset %d", offset));
|
||||||
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:
|
||||||
|
|
||||||
exit:
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int HttpGetDemoPage(httpd_request_t *req) {
|
static int HttpGetIndexPage(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
|
int total_sz = sizeof(web_index_html);
|
||||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http demo 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 demo body."));
|
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, HTTP_CONTENT_HTML_ZIP);
|
||||||
exit:
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,14 +129,15 @@ static int HttpGetAssets(httpd_request_t *req) {
|
|||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
char *file_name = strstr(req->filename, "/assets/");
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
//http_log("HttpGetAssets url[%s] file_name[%s]", req->filename, file_name);
|
|
||||||
|
|
||||||
int total_sz = 0;
|
int total_sz = 0;
|
||||||
const unsigned char *file_data = NULL;
|
const unsigned char *file_data = NULL;
|
||||||
const char *content_type = HTTP_CONTENT_JS_ZIP;
|
const char *content_type = HTTP_CONTENT_JS_ZIP;
|
||||||
|
|
||||||
if (strcmp(file_name + 8, "js_pack.js") == 0) {
|
if (strcmp(file_name + 8, "js_pack.js") == 0) {
|
||||||
total_sz = sizeof(js_pack);
|
total_sz = sizeof(js_pack);
|
||||||
file_data = js_pack;
|
file_data = js_pack;
|
||||||
@@ -133,34 +145,53 @@ static int HttpGetAssets(httpd_request_t *req) {
|
|||||||
total_sz = sizeof(css_pack);
|
total_sz = sizeof(css_pack);
|
||||||
file_data = css_pack;
|
file_data = css_pack;
|
||||||
content_type = HTTP_CONTENT_CSS_ZIP;
|
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);
|
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);
|
err = send_in_chunks(req->sock, file_data, total_sz);
|
||||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets body."));
|
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset body."));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int HttpGetTc1Status(httpd_request_t *req) {
|
static int HttpGetTc1Status(httpd_request_t *req) {
|
||||||
char *sockets = GetSocketStatus();
|
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,
|
sprintf(tc1_status, TC1_STATUS_JSON, sockets, ip_status.mode,
|
||||||
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
|
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
|
||||||
user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT,
|
user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT,
|
||||||
MQTT_SERVER_USR, MQTT_SERVER_PWD,
|
MQTT_SERVER_USR, MQTT_SERVER_PWD,
|
||||||
VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, user_config->mqtt_report_freq,
|
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;
|
OSStatus err = kNoErr;
|
||||||
send_http(tc1_status, strlen(tc1_status), exit, &err);
|
send_http(tc1_status, strlen(tc1_status), exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (socket_names) free(socket_names);
|
||||||
if (tc1_status) free(tc1_status);
|
if (tc1_status) free(tc1_status);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -183,6 +214,179 @@ static int HttpSetSocketStatus(httpd_request_t *req) {
|
|||||||
return err;
|
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) {
|
static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
char buf[16];
|
char buf[16];
|
||||||
@@ -204,9 +408,21 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
|
|||||||
|
|
||||||
char *powers = GetPowerRecord(idx);
|
char *powers = GetPowerRecord(idx);
|
||||||
char *sockets = GetSocketStatus();
|
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,
|
sprintf(power_info_json, POWER_INFO_JSON, sockets, power_record.idx, PW_NUM, p_count, powers,
|
||||||
up_time,user_config->power_led_enabled,RelayOut()?1:0);
|
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);
|
send_http(power_info_json, strlen(power_info_json), exit, &err);
|
||||||
|
if (socket_names) free(socket_names);
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -219,19 +435,62 @@ static int HttpGetWifiConfig(httpd_request_t *req) {
|
|||||||
return err;
|
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) {
|
static int HttpSetWifiConfig(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
int buf_size = 97;
|
char *buf = malloc(256);
|
||||||
char *buf = malloc(buf_size);
|
char *ssid_enc = malloc(128);
|
||||||
|
char *key_enc = malloc(128);
|
||||||
|
char *wifi_ssid = malloc(128);
|
||||||
|
char *wifi_key = malloc(128);
|
||||||
int mode = -1;
|
int mode = -1;
|
||||||
char *wifi_ssid = malloc(32);
|
|
||||||
char *wifi_key = malloc(32);
|
|
||||||
|
|
||||||
err = httpd_get_data(req, buf, buf_size);
|
|
||||||
|
|
||||||
|
err = httpd_get_data(req, buf, 256);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
|
// 假设 httpd_get_data(req, buf, 256);
|
||||||
sscanf(buf, "%d %s %s", &mode, wifi_ssid, wifi_key);
|
// 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) {
|
if (mode == 1) {
|
||||||
WifiConnect(wifi_ssid, wifi_key);
|
WifiConnect(wifi_ssid, wifi_key);
|
||||||
} else {
|
} 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);
|
sscanf(buf, "%s %d %s %s", MQTT_SERVER, &MQTT_SERVER_PORT, MQTT_SERVER_USR, MQTT_SERVER_PWD);
|
||||||
mico_system_context_update(sys_config);
|
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);
|
send_http("OK", 2, exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -328,6 +590,7 @@ static int HttpGetMqttReportFreq(httpd_request_t *req) {
|
|||||||
send_http(freq, strlen(freq), exit, &err);
|
send_http(freq, strlen(freq), exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (freq) free(freq);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,12 +613,21 @@ static int HttpGetTasks(httpd_request_t *req) {
|
|||||||
return err;
|
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) {
|
static int HttpAddTask(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
//1577369623 4 0
|
//1577369623 4 0
|
||||||
char buf[16] = {0};
|
char buf[20] = {0};
|
||||||
err = httpd_get_data(req, buf, 16);
|
err = httpd_get_data(req, buf, 20);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
|
|
||||||
pTimedTask task = NewTask();
|
pTimedTask task = NewTask();
|
||||||
@@ -364,20 +636,19 @@ static int HttpAddTask(httpd_request_t *req) {
|
|||||||
send_http(mess, strlen(mess), exit, &err);
|
send_http(mess, strlen(mess), exit, &err);
|
||||||
return 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)",
|
&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->weekday);
|
||||||
task->socket_idx--;
|
|
||||||
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|
||||||
|| task->socket_idx < 0 || task->socket_idx > 5
|
|| task->operation < 0 || task->operation > 11) { http_log("AddTask Error!");
|
||||||
|| (task->on != 0 && task->on != 1)) { http_log("AddTask Error!");
|
|
||||||
re = 0;
|
re = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mess = (re == 4 && AddTask(task)) ? "OK" : "NO";
|
char *mess = (re == 4 && AddTask(task)) ? "OK" : "NO";
|
||||||
|
|
||||||
send_http(mess, strlen(mess), exit, &err);
|
send_http(mess, strlen(mess), exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -409,6 +680,7 @@ static int LedStatus(httpd_request_t *req) {
|
|||||||
send_http(led, strlen(led), exit, &err);
|
send_http(led, strlen(led), exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (led) free(led);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,7 +709,7 @@ static int LedSetEnabled(httpd_request_t *req) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int TotalSocketSetEnabled(httpd_request_t *req){
|
static int TotalSocketSetEnabled(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
int buf_size = 97;
|
int buf_size = 97;
|
||||||
@@ -486,7 +758,6 @@ static int OtaStart(httpd_request_t *req) {
|
|||||||
|
|
||||||
const struct httpd_wsgi_call g_app_handlers[] = {
|
const struct httpd_wsgi_call g_app_handlers[] = {
|
||||||
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
||||||
{"/demo", HTTPD_HDR_DEFORT, 0, HttpGetDemoPage, NULL, NULL, NULL},
|
|
||||||
{"/assets", HTTPD_HDR_ADD_SERVER |
|
{"/assets", HTTPD_HDR_ADD_SERVER |
|
||||||
HTTPD_HDR_ADD_CONN_CLOSE, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetAssets, NULL, NULL, NULL},
|
HTTPD_HDR_ADD_CONN_CLOSE, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetAssets, NULL, NULL, NULL},
|
||||||
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
||||||
@@ -502,6 +773,11 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
|||||||
{"/ota", HTTPD_HDR_DEFORT, 0, Otastatus, OtaStart, NULL, NULL},
|
{"/ota", HTTPD_HDR_DEFORT, 0, Otastatus, OtaStart, NULL, NULL},
|
||||||
{"/led", HTTPD_HDR_DEFORT, 0, LedStatus, LedSetEnabled, NULL, NULL},
|
{"/led", HTTPD_HDR_DEFORT, 0, LedStatus, LedSetEnabled, NULL, NULL},
|
||||||
{"/socketAll", HTTPD_HDR_DEFORT, 0, NULL, TotalSocketSetEnabled, 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);
|
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
||||||
|
|||||||
@@ -64,12 +64,16 @@
|
|||||||
'gateway':'%s',\
|
'gateway':'%s',\
|
||||||
'reportFreq':'%d',\
|
'reportFreq':'%d',\
|
||||||
'ledEnabled':%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,'total_switch_on':%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
@@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "mico.h"
|
||||||
|
|
||||||
|
|
||||||
#include"http_server/web_log.h"
|
#include"http_server/web_log.h"
|
||||||
|
|
||||||
@@ -36,6 +38,9 @@ char* GetLogRecord()
|
|||||||
tmp += strlen(tmp);
|
tmp += strlen(tmp);
|
||||||
if (!log_record.logs[i%LOG_NUM]) continue;
|
if (!log_record.logs[i%LOG_NUM]) continue;
|
||||||
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
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;
|
return log_record_str;
|
||||||
}
|
}
|
||||||
|
|||||||
48
TC1/main.c
48
TC1/main.c
@@ -4,12 +4,12 @@
|
|||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
#include "TimeUtils.h"
|
#include "TimeUtils.h"
|
||||||
|
#include "mico_system.h"
|
||||||
|
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "user_wifi.h"
|
#include "user_wifi.h"
|
||||||
#include "time_server/user_rtc.h"
|
#include "time_server/user_rtc.h"
|
||||||
#include "user_power.h"
|
#include "user_power.h"
|
||||||
#include "mqtt_server/user_mqtt_client.h"
|
|
||||||
#include "http_server/app_httpd.h"
|
#include "http_server/app_httpd.h"
|
||||||
#include "timed_task/timed_task.h"
|
#include "timed_task/timed_task.h"
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ char rtc_init = 0; //sntp校时成功标志位
|
|||||||
uint32_t total_time = 0;
|
uint32_t total_time = 0;
|
||||||
char str_mac[16] = {0};
|
char str_mac[16] = {0};
|
||||||
int last_check_day = 0;
|
int last_check_day = 0;
|
||||||
|
int childLockEnabled = 0;
|
||||||
|
|
||||||
system_config_t *sys_config;
|
system_config_t *sys_config;
|
||||||
user_config_t *user_config;
|
user_config_t *user_config;
|
||||||
@@ -43,12 +44,23 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
|||||||
userConfigDefault->p_count_1_day_ago = 0;
|
userConfigDefault->p_count_1_day_ago = 0;
|
||||||
userConfigDefault->power_led_enabled = 1;
|
userConfigDefault->power_led_enabled = 1;
|
||||||
userConfigDefault->version = USER_CONFIG_VERSION;
|
userConfigDefault->version = USER_CONFIG_VERSION;
|
||||||
|
set_key_map(userConfigDefault->user,1, SWITCH_ALL_SOCKETS, NO_FUNCTION);
|
||||||
int i;
|
for (int i = 2; i < 32; i++) {
|
||||||
for (i = 0; i < SOCKET_NUM; i++) {
|
int longFunc = NO_FUNCTION;
|
||||||
userConfigDefault->socket_status[i] = 1;
|
//出厂设置,长按5秒开启配网模式,长按10秒恢复出厂设置
|
||||||
|
if (i >=5 && i< 10) {
|
||||||
|
longFunc = CONFIG_WIFI;
|
||||||
|
} else if (i >= 10 && i< 15) {
|
||||||
|
longFunc = RESET_SYSTEM;
|
||||||
}
|
}
|
||||||
for (i = 0; i < MAX_TASK_NUM; i++) {
|
set_key_map(userConfigDefault->user,i, NO_FUNCTION, longFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
userConfigDefault->timed_tasks[i].on_use = false;
|
||||||
}
|
}
|
||||||
mico_system_context_update(sys_config);
|
mico_system_context_update(sys_config);
|
||||||
@@ -59,12 +71,14 @@ void recordDailyPCount() {
|
|||||||
mico_utc_time_t utc_time;
|
mico_utc_time_t utc_time;
|
||||||
mico_time_get_utc_time(&utc_time);
|
mico_time_get_utc_time(&utc_time);
|
||||||
utc_time += 28800;
|
utc_time += 28800;
|
||||||
struct tm * current_time = localtime((const time_t *) &utc_time);
|
struct tm *current_time = localtime((const time_t *) &utc_time);
|
||||||
// 判断上次检查的时间与当前时间的日期是否不同
|
// 判断上次检查的时间与当前时间的日期是否不同
|
||||||
if (last_check_day != 0) {
|
if (last_check_day != 0) {
|
||||||
// 如果日期发生变化(即跨天了),则进行记录
|
// 如果日期发生变化(即跨天了),则进行记录
|
||||||
if (current_time->tm_mday != last_check_day) {
|
if (current_time->tm_mday != last_check_day) { tc1_log(
|
||||||
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);
|
"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! ");
|
// tc1_log("WARNGIN: pcount day changed! ");
|
||||||
// 记录数据
|
// 记录数据
|
||||||
@@ -81,8 +95,8 @@ void recordDailyPCount() {
|
|||||||
} else {
|
} else {
|
||||||
// tc1_log("WARNGIN: pcount day not changed , waiting for next run! ");
|
// tc1_log("WARNGIN: pcount day not changed , waiting for next run! ");
|
||||||
}
|
}
|
||||||
}else{
|
} else { tc1_log("WARNGIN: now day %d hour %d min %d ,lastCheck day %d", current_time->tm_mday,
|
||||||
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);
|
current_time->tm_hour, current_time->tm_min, last_check_day);
|
||||||
}
|
}
|
||||||
// 更新上次检查时间
|
// 更新上次检查时间
|
||||||
last_check_day = current_time->tm_mday;
|
last_check_day = current_time->tm_mday;
|
||||||
@@ -132,7 +146,7 @@ int application_start(void) {
|
|||||||
MicoGpioInitialize((mico_gpio_t) Button, INPUT_PULL_UP);
|
MicoGpioInitialize((mico_gpio_t) Button, INPUT_PULL_UP);
|
||||||
if (!MicoGpioInputGet(Button)) { //开机时按钮状态
|
if (!MicoGpioInputGet(Button)) { //开机时按钮状态
|
||||||
tc1_log("press ap_init");
|
tc1_log("press ap_init");
|
||||||
ApInit(false);
|
ApInit(true);
|
||||||
open_ap = true;
|
open_ap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +157,7 @@ int application_start(void) {
|
|||||||
}
|
}
|
||||||
MicoSysLed(0);
|
MicoSysLed(0);
|
||||||
|
|
||||||
|
childLockEnabled = (int) user_config->user[0];
|
||||||
if (user_config->version != USER_CONFIG_VERSION) { tc1_log("WARNGIN: user params restored!");
|
if (user_config->version != USER_CONFIG_VERSION) { tc1_log("WARNGIN: user params restored!");
|
||||||
err = mico_system_context_restore(sys_config);
|
err = mico_system_context_restore(sys_config);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
@@ -152,7 +167,7 @@ int application_start(void) {
|
|||||||
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac + 8);
|
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
tc1_log("user:%s", user_config->user);tc1_log("device name:%s",
|
tc1_log("device name:%s",
|
||||||
sys_config->micoSystemConfig.name);tc1_log(
|
sys_config->micoSystemConfig.name);tc1_log(
|
||||||
"mqtt_ip:%s", user_config->mqtt_ip);tc1_log("mqtt_port:%d",
|
"mqtt_ip:%s", user_config->mqtt_ip);tc1_log("mqtt_port:%d",
|
||||||
user_config->mqtt_port);tc1_log(
|
user_config->mqtt_port);tc1_log(
|
||||||
@@ -170,8 +185,6 @@ int application_start(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyInit();
|
KeyInit();
|
||||||
err = UserMqttInit();
|
|
||||||
require_noerr(err, exit);
|
|
||||||
err = UserRtcInit();
|
err = UserRtcInit();
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
PowerInit();
|
PowerInit();
|
||||||
@@ -181,12 +194,12 @@ int application_start(void) {
|
|||||||
|
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
|
||||||
(mico_thread_function_t) schedule_p_count_task,
|
(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.");
|
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",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
|
||||||
(mico_thread_function_t) reportMqttPowerInfoThread,
|
(mico_thread_function_t) reportMqttPowerInfoThread,
|
||||||
0x2000, 0);
|
0x800, 0);
|
||||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
|
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +208,6 @@ int application_start(void) {
|
|||||||
if (user_config->task_top && now >= user_config->task_top->prs_time) {
|
if (user_config->task_top && now >= user_config->task_top->prs_time) {
|
||||||
ProcessTask();
|
ProcessTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
mico_thread_msleep(1000);
|
mico_thread_msleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
TC1/main.h
14
TC1/main.h
@@ -16,17 +16,17 @@
|
|||||||
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
|
#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 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 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 SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。
|
||||||
|
|
||||||
#define SOCKET_NAME_LENGTH 32
|
#define SOCKET_NAME_LENGTH 64
|
||||||
#define SOCKET_NUM 6 //插座数量
|
#define SOCKET_NUM 6 //插座数量
|
||||||
|
|
||||||
#define Led MICO_GPIO_5
|
#define Led MICO_GPIO_5
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#define Relay_ON 1
|
#define Relay_ON 1
|
||||||
#define Relay_OFF 0
|
#define Relay_OFF 0
|
||||||
|
#define Relay_TOGGLE -1
|
||||||
|
|
||||||
#define Relay_0 MICO_GPIO_6
|
#define Relay_0 MICO_GPIO_6
|
||||||
#define Relay_1 MICO_GPIO_8
|
#define Relay_1 MICO_GPIO_8
|
||||||
@@ -51,6 +52,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
char version;
|
char version;
|
||||||
char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX];
|
char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX];
|
||||||
|
char socket_names[SOCKET_NUM][SOCKET_NAME_LENGTH];
|
||||||
int mqtt_port;
|
int mqtt_port;
|
||||||
int mqtt_report_freq;
|
int mqtt_report_freq;
|
||||||
char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX];
|
char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX];
|
||||||
@@ -74,5 +76,7 @@ extern char str_mac[16];
|
|||||||
extern system_config_t* sys_config;
|
extern system_config_t* sys_config;
|
||||||
extern user_config_t* user_config;
|
extern user_config_t* user_config;
|
||||||
extern mico_gpio_t Relay[Relay_NUM];
|
extern mico_gpio_t Relay[Relay_NUM];
|
||||||
|
extern int childLockEnabled;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ mico_queue_t mqtt_msg_send_queue = NULL;
|
|||||||
|
|
||||||
Client c; // mqtt client object
|
Client c; // mqtt client object
|
||||||
Network n; // socket network for mqtt client
|
Network n; // socket network for mqtt client
|
||||||
|
volatile bool mqtt_thread_should_exit = false;
|
||||||
|
|
||||||
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
|
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
|
||||||
//static mico_timed_event_t mqtt_client_send_event;
|
//static mico_timed_event_t mqtt_client_send_event;
|
||||||
@@ -76,6 +77,8 @@ void UserMqttTimerFunc(void *arg) {
|
|||||||
case 0:
|
case 0:
|
||||||
UserMqttHassAutoLed();
|
UserMqttHassAutoLed();
|
||||||
UserMqttHassAutoTotalSocket();
|
UserMqttHassAutoTotalSocket();
|
||||||
|
UserMqttHassAutoChildLock();
|
||||||
|
UserMqttHassAutoRebootButton();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
@@ -96,10 +99,32 @@ void UserMqttTimerFunc(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSStatus UserMqttDeInit(void) {
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
|
// 1. 请求线程退出
|
||||||
|
mqtt_thread_should_exit = true;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_mqtt_msg_send_queue(void) {
|
||||||
|
if(mqtt_msg_send_queue == NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void *msg = NULL;
|
||||||
|
while (mico_rtos_is_queue_empty(&mqtt_msg_send_queue) == false) {
|
||||||
|
if (mico_rtos_pop_from_queue(&mqtt_msg_send_queue, &msg, 0) == kNoErr) {
|
||||||
|
if (msg) free(msg); // 释放消息内存,避免泄漏
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Application entrance */
|
/* Application entrance */
|
||||||
OSStatus UserMqttInit(void) {
|
OSStatus UserMqttInit(void) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
if(mqtt_msg_send_queue != NULL)
|
||||||
|
return err;
|
||||||
sprintf(topic_set, MQTT_CLIENT_SUB_TOPIC1);
|
sprintf(topic_set, MQTT_CLIENT_SUB_TOPIC1);
|
||||||
sprintf(topic_state, MQTT_CLIENT_PUB_TOPIC, str_mac);
|
sprintf(topic_state, MQTT_CLIENT_PUB_TOPIC, str_mac);
|
||||||
//TODO size:0x800
|
//TODO size:0x800
|
||||||
@@ -134,13 +159,32 @@ OSStatus UserMqttInit(void) {
|
|||||||
static OSStatus UserMqttClientRelease(Client *c, Network *n) {
|
static OSStatus UserMqttClientRelease(Client *c, Network *n) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
if (c->isconnected) MQTTDisconnect(c);
|
if (c == NULL || n == NULL) return kParamErr;
|
||||||
|
|
||||||
n->disconnect(n); // close connection
|
if (c->isconnected) {
|
||||||
|
MQTTDisconnect(c);
|
||||||
|
c->isconnected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (MQTT_SUCCESS != MQTTClientDeinit(c)) { mqtt_log("MQTTClientDeinit failed!");
|
if (c->buf) {
|
||||||
|
free(c->buf);
|
||||||
|
c->buf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c->readbuf) {
|
||||||
|
free(c->readbuf);
|
||||||
|
c->readbuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n->disconnect) {
|
||||||
|
n->disconnect(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MQTT_SUCCESS != MQTTClientDeinit(c)) {
|
||||||
|
mqtt_log("MQTTClientDeinit failed!");
|
||||||
err = kDeletedErr;
|
err = kDeletedErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +218,14 @@ static OSStatus MqttMsgPublish(Client *c, const char *topic, char qos, char reta
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void registerMqttEvents(void) {
|
||||||
|
if(timer_status !=0){
|
||||||
|
mico_stop_timer(&timer_handle);
|
||||||
|
}
|
||||||
|
timer_status = 0;
|
||||||
|
mico_start_timer(&timer_handle);
|
||||||
|
}
|
||||||
|
|
||||||
void MqttClientThread(mico_thread_arg_t arg) {
|
void MqttClientThread(mico_thread_arg_t arg) {
|
||||||
OSStatus err = kUnknownErr;
|
OSStatus err = kUnknownErr;
|
||||||
|
|
||||||
@@ -195,16 +247,18 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
|
|
||||||
/* create msg send queue event fd */
|
/* create msg send queue event fd */
|
||||||
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
|
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
|
||||||
|
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||||
|
|
||||||
require_action(msg_send_event_fd >= 0, exit,
|
require_action(msg_send_event_fd >= 0, exit,
|
||||||
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
|
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
|
||||||
|
mqtt_thread_should_exit = false;
|
||||||
MQTT_start:
|
MQTT_start:
|
||||||
|
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
/* 1. create network connection */
|
/* 1. create network connection */
|
||||||
ssl_settings.ssl_enable = false;
|
ssl_settings.ssl_enable = false;
|
||||||
LinkStatusTypeDef LinkStatus;
|
LinkStatusTypeDef LinkStatus;
|
||||||
while (1) {
|
while (!mqtt_thread_should_exit) {
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
mico_rtos_thread_sleep(3);
|
mico_rtos_thread_sleep(3);
|
||||||
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
|
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
|
||||||
@@ -221,7 +275,8 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
if (rc == MQTT_SUCCESS) break;
|
if (rc == MQTT_SUCCESS) break;
|
||||||
|
|
||||||
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
||||||
}mqtt_log("MQTT network connect success!");
|
}
|
||||||
|
mqtt_log("MQTT network connect success!");
|
||||||
|
|
||||||
/* 2. init mqtt client */
|
/* 2. init mqtt client */
|
||||||
//c.heartbeat_retry_max = 2;
|
//c.heartbeat_retry_max = 2;
|
||||||
@@ -242,7 +297,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
rc = MQTTConnect(&c, &connectData);
|
rc = MQTTConnect(&c, &connectData);
|
||||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client connect err.");
|
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client connect err.");
|
||||||
|
|
||||||
mqtt_log("MQTT client connect success!");
|
mqtt_log("MQTT client connect success, result: %d ", rc);
|
||||||
|
|
||||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||||
|
|
||||||
@@ -259,11 +314,12 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserMqttSendLedState();
|
UserMqttSendLedState();
|
||||||
|
UserMqttSendTotalSocketState();
|
||||||
|
UserMqttSendChildLockState();
|
||||||
|
|
||||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
registerMqttEvents();
|
||||||
mico_start_timer(&timer_handle);
|
|
||||||
/* 5. client loop for recv msg && keepalive */
|
/* 5. client loop for recv msg && keepalive */
|
||||||
while (1) {
|
while (!mqtt_thread_should_exit) {
|
||||||
isconnect = true;
|
isconnect = true;
|
||||||
no_mqtt_msg_exchange = true;
|
no_mqtt_msg_exchange = true;
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
@@ -289,13 +345,12 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
err = MqttMsgPublish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
err = MqttMsgPublish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
||||||
(const unsigned char *) p_send_msg->data,
|
(const unsigned char *) p_send_msg->data,
|
||||||
p_send_msg->datalen);
|
p_send_msg->datalen);
|
||||||
|
free(p_send_msg);
|
||||||
|
p_send_msg = NULL;
|
||||||
require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT publish data err");
|
require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT publish data err");
|
||||||
|
|
||||||
//mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].", p_send_msg->topic, p_send_msg->datalen);
|
//mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].", p_send_msg->topic, p_send_msg->datalen);
|
||||||
no_mqtt_msg_exchange = false;
|
no_mqtt_msg_exchange = false;
|
||||||
free(p_send_msg);
|
|
||||||
p_send_msg = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +366,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err);
|
mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err);
|
||||||
|
|
||||||
timer_status = 100;
|
timer_status = 100;
|
||||||
|
clear_mqtt_msg_send_queue();
|
||||||
UserMqttClientRelease(&c, &n);
|
UserMqttClientRelease(&c, &n);
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
UserLedSet(-1);
|
UserLedSet(-1);
|
||||||
@@ -320,10 +375,12 @@ mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d,
|
|||||||
mico_rtos_thread_sleep(5);
|
mico_rtos_thread_sleep(5);
|
||||||
goto MQTT_start;
|
goto MQTT_start;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
isconnect = false;mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
isconnect = false;
|
||||||
|
mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
||||||
UserMqttClientRelease(&c, &n);
|
UserMqttClientRelease(&c, &n);
|
||||||
mico_rtos_delete_thread(NULL);
|
mico_rtos_delete_thread(NULL); // 自删
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback, msg received from mqtt server
|
// callback, msg received from mqtt server
|
||||||
@@ -406,12 +463,27 @@ void ProcessHaCmd(char *cmd) {
|
|||||||
UserMqttSendSocketState(i);
|
UserMqttSendSocketState(i);
|
||||||
}
|
}
|
||||||
UserMqttSendTotalSocketState();
|
UserMqttSendTotalSocketState();
|
||||||
|
}else if (strcmp(cmd, "set childLock") == ' ') {
|
||||||
|
int on;
|
||||||
|
sscanf(cmd, "set childLock %s %d", mac, &on);
|
||||||
|
if (strcmp(mac, str_mac)) return;mqtt_log("set childLock on[%d]", on);
|
||||||
|
user_config->user[0] = on;
|
||||||
|
childLockEnabled = on;
|
||||||
|
UserMqttSendChildLockState();
|
||||||
|
mico_system_context_update(sys_config);
|
||||||
|
}else if (strcmp(cmd, "reboot") == ' ') {
|
||||||
|
sscanf(cmd, "reboot %s", mac);
|
||||||
|
if (strcmp(mac, str_mac)) return;
|
||||||
|
MicoSystemReboot(); // 立即重启设备
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
||||||
OSStatus err = kUnknownErr;
|
OSStatus err = kUnknownErr;
|
||||||
p_mqtt_send_msg_t p_send_msg = NULL;
|
p_mqtt_send_msg_t p_send_msg = NULL;
|
||||||
|
if(mqtt_msg_send_queue == NULL|| !isconnect){
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
// mqtt_log("======App prepare to send ![%d]======", MicoGetMemoryInfo()->free_memory);
|
// mqtt_log("======App prepare to send ![%d]======", MicoGetMemoryInfo()->free_memory);
|
||||||
|
|
||||||
@@ -494,29 +566,47 @@ OSStatus UserMqttSendLedState(void) {
|
|||||||
return oss_status;
|
return oss_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSStatus UserMqttSendChildLockState(void) {
|
||||||
|
char *send_buf = malloc(64);
|
||||||
|
char *topic_buf = malloc(64);
|
||||||
|
OSStatus oss_status = kUnknownErr;
|
||||||
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
|
sprintf(topic_buf, "homeassistant/switch/%s/childLock/state", str_mac);
|
||||||
|
sprintf(send_buf, "set childLock %s %d", str_mac, childLockEnabled);
|
||||||
|
oss_status = UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
}
|
||||||
|
if (send_buf) free(send_buf);
|
||||||
|
if (topic_buf) free(topic_buf);
|
||||||
|
|
||||||
|
return oss_status;
|
||||||
|
}
|
||||||
|
|
||||||
//hass mqtt鑷姩鍙戠幇鏁版嵁寮<E5B581>鍏冲彂閫<E5BD82>
|
//hass mqtt鑷姩鍙戠幇鏁版嵁寮<E5B581>鍏冲彂閫<E5BD82>
|
||||||
void UserMqttHassAuto(char socket_id) {
|
void UserMqttHassAuto(char socket_id) {
|
||||||
socket_id--;
|
socket_id--;
|
||||||
char *send_buf = NULL;
|
char *send_buf = NULL;
|
||||||
char *topic_buf = NULL;
|
char *topic_buf = NULL;
|
||||||
send_buf = (char *) malloc(1024);
|
send_buf = (char *) malloc(600);
|
||||||
topic_buf = (char *) malloc(64);
|
topic_buf = (char *) malloc(64);
|
||||||
if (send_buf != NULL && topic_buf != NULL) {
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/config", str_mac, socket_id);
|
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/config", str_mac, socket_id);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_Socket_%d\","
|
"{\"name\":\"%s\","
|
||||||
"\"uniq_id\":\"%s_s%d\","
|
"\"uniq_id\":\"tc1_%s_s%d\","
|
||||||
|
"\"object_id\":\"tc1_%s_s%d\","
|
||||||
"\"stat_t\":\"homeassistant/switch/%s/socket_%d/state\","
|
"\"stat_t\":\"homeassistant/switch/%s/socket_%d/state\","
|
||||||
"\"cmd_t\":\"device/ztc1/set\","
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
"\"pl_on\":\"set socket %s %d 1\","
|
"\"pl_on\":\"set socket %s %d 1\","
|
||||||
"\"pl_off\":\"set socket %s %d 0\","
|
"\"pl_off\":\"set socket %s %d 0\","
|
||||||
|
"\"device_class\":\"outlet\","
|
||||||
"\"device\":{"
|
"\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, socket_id + 1, str_mac, socket_id, str_mac, socket_id, str_mac,
|
user_config->socket_names[(int)socket_id], str_mac, socket_id,str_mac, socket_id, str_mac, socket_id,
|
||||||
socket_id, str_mac, socket_id, str_mac, str_mac);
|
str_mac,
|
||||||
|
socket_id, str_mac, socket_id, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf)
|
if (send_buf)
|
||||||
@@ -525,26 +615,84 @@ void UserMqttHassAuto(char socket_id) {
|
|||||||
free(topic_buf);
|
free(topic_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UserMqttHassAutoRebootButton(void) {
|
||||||
|
char *send_buf = NULL;
|
||||||
|
char *topic_buf = NULL;
|
||||||
|
send_buf = (char *) malloc(600);
|
||||||
|
topic_buf = (char *) malloc(64);
|
||||||
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
|
// 重启按钮配置
|
||||||
|
sprintf(topic_buf, "homeassistant/button/%s/reboot/config", str_mac);
|
||||||
|
sprintf(send_buf,
|
||||||
|
"{\"name\":\"重启设备\","
|
||||||
|
"\"uniq_id\":\"tc1_%s_reboot\","
|
||||||
|
"\"object_id\":\"tc1_%s_reboot\","
|
||||||
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
|
"\"pl_prs\":\"reboot %s\","
|
||||||
|
"\"device\":{"
|
||||||
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
|
"\"name\":\"%s\","
|
||||||
|
"\"model\":\"TC1\","
|
||||||
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
|
str_mac,str_mac,str_mac,str_mac, sys_config->micoSystemConfig.name);
|
||||||
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
}
|
||||||
|
if (send_buf) free(send_buf);
|
||||||
|
if (topic_buf) free(topic_buf);
|
||||||
|
}
|
||||||
|
|
||||||
void UserMqttHassAutoLed(void) {
|
void UserMqttHassAutoLed(void) {
|
||||||
char *send_buf = NULL;
|
char *send_buf = NULL;
|
||||||
char *topic_buf = NULL;
|
char *topic_buf = NULL;
|
||||||
send_buf = (char *) malloc(1024);
|
send_buf = (char *) malloc(600);
|
||||||
topic_buf = (char *) malloc(64);
|
topic_buf = (char *) malloc(64);
|
||||||
if (send_buf != NULL && topic_buf != NULL) {
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
|
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_Led\","
|
"{\"name\":\"LED指示灯\","
|
||||||
"\"uniq_id\":\"%s_led\","
|
"\"uniq_id\":\"tc1_%s_led\","
|
||||||
|
"\"object_id\":\"tc1_%s_led\","
|
||||||
"\"stat_t\":\"homeassistant/switch/%s/led/state\","
|
"\"stat_t\":\"homeassistant/switch/%s/led/state\","
|
||||||
"\"cmd_t\":\"device/ztc1/set\","
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
"\"pl_on\":\"set led %s 1\","
|
"\"pl_on\":\"set led %s 1\","
|
||||||
"\"pl_off\":\"set led %s 0\","
|
"\"pl_off\":\"set led %s 0\","
|
||||||
|
"\"device_class\":\"outlet\","
|
||||||
"\"device\":{"
|
"\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
str_mac,str_mac,str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
}
|
||||||
|
if (send_buf)
|
||||||
|
free(send_buf);
|
||||||
|
if (topic_buf)
|
||||||
|
free(topic_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserMqttHassAutoChildLock(void) {
|
||||||
|
char *send_buf = NULL;
|
||||||
|
char *topic_buf = NULL;
|
||||||
|
send_buf = (char *) malloc(600);
|
||||||
|
topic_buf = (char *) malloc(64);
|
||||||
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
|
sprintf(topic_buf, "homeassistant/switch/%s/childLock/config", str_mac);
|
||||||
|
sprintf(send_buf,
|
||||||
|
"{\"name\":\"童锁\","
|
||||||
|
"\"uniq_id\":\"tc1_%s_child_lock\","
|
||||||
|
"\"object_id\":\"tc1_%s_child_lock\","
|
||||||
|
"\"stat_t\":\"homeassistant/switch/%s/childLock/state\","
|
||||||
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
|
"\"pl_on\":\"set childLock %s 1\","
|
||||||
|
"\"pl_off\":\"set childLock %s 0\","
|
||||||
|
"\"device_class\":\"outlet\","
|
||||||
|
"\"device\":{"
|
||||||
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
|
"\"name\":\"%s\","
|
||||||
|
"\"model\":\"TC1\","
|
||||||
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
|
str_mac,str_mac,str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf)
|
if (send_buf)
|
||||||
@@ -556,23 +704,25 @@ void UserMqttHassAutoLed(void) {
|
|||||||
void UserMqttHassAutoTotalSocket(void) {
|
void UserMqttHassAutoTotalSocket(void) {
|
||||||
char *send_buf = NULL;
|
char *send_buf = NULL;
|
||||||
char *topic_buf = NULL;
|
char *topic_buf = NULL;
|
||||||
send_buf = (char *) malloc(1024);
|
send_buf = (char *) malloc(600);
|
||||||
topic_buf = (char *) malloc(64);
|
topic_buf = (char *) malloc(64);
|
||||||
if (send_buf != NULL && topic_buf != NULL) {
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
sprintf(topic_buf, "homeassistant/switch/%s/total_socket/config", str_mac);
|
sprintf(topic_buf, "homeassistant/switch/%s/total_socket/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_TotalSocket\","
|
"{\"name\":\"总开关\","
|
||||||
"\"uniq_id\":\"%s_total_socket\","
|
"\"uniq_id\":\"tc1_%s_total_socket\","
|
||||||
|
"\"object_id\":\"tc1_%s_total_socket\","
|
||||||
"\"stat_t\":\"homeassistant/switch/%s/total_socket/state\","
|
"\"stat_t\":\"homeassistant/switch/%s/total_socket/state\","
|
||||||
"\"cmd_t\":\"device/ztc1/set\","
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
"\"pl_on\":\"set total_socket %s 1\","
|
"\"pl_on\":\"set total_socket %s 1\","
|
||||||
"\"pl_off\":\"set total_socket %s 0\","
|
"\"pl_off\":\"set total_socket %s 0\","
|
||||||
|
"\"device_class\":\"outlet\","
|
||||||
"\"device\":{"
|
"\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf)
|
if (send_buf)
|
||||||
@@ -585,66 +735,87 @@ void UserMqttHassAutoTotalSocket(void) {
|
|||||||
void UserMqttHassAutoPower(void) {
|
void UserMqttHassAutoPower(void) {
|
||||||
char *send_buf = NULL;
|
char *send_buf = NULL;
|
||||||
char *topic_buf = NULL;
|
char *topic_buf = NULL;
|
||||||
send_buf = malloc(1024);
|
send_buf = malloc(600);
|
||||||
topic_buf = malloc(128);
|
topic_buf = malloc(128);
|
||||||
if (send_buf != NULL && topic_buf != NULL) {
|
if (send_buf != NULL && topic_buf != NULL) {
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/config", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/power/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_Power\","
|
"{\"name\":\"功率\","
|
||||||
"\"uniq_id\":\"%s_p\","
|
"\"uniq_id\":\"tc1_%s_p\","
|
||||||
|
"\"object_id\":\"tc1_%s_p\","
|
||||||
"\"state_topic\":\"homeassistant/sensor/%s/power/state\","
|
"\"state_topic\":\"homeassistant/sensor/%s/power/state\","
|
||||||
"\"unit_of_measurement\":\"W\","
|
"\"unit_of_measurement\":\"W\","
|
||||||
"\"icon\":\"mdi:gauge\","
|
"\"icon\":\"mdi:gauge\","
|
||||||
"\"value_template\":\"{{ value_json.power }}\",""\"device\":{"
|
"\"value_template\":\"{{ value_json.power }}\",""\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumption/config", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumption/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_PowerConsumption\","
|
"{\"name\":\"总耗电量\","
|
||||||
"\"uniq_id\":\"%s_pc\","
|
"\"uniq_id\":\"tc1_%s_pc\","
|
||||||
|
"\"object_id\":\"tc1_%s_pc\","
|
||||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumption/state\","
|
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumption/state\","
|
||||||
"\"unit_of_measurement\":\"kWh\","
|
"\"unit_of_measurement\":\"kWh\","
|
||||||
"\"icon\":\"mdi:fence-electric\","
|
"\"icon\":\"mdi:fence-electric\","
|
||||||
"\"value_template\":\"{{ value_json.powerConsumption }}\",""\"device\":{"
|
"\"value_template\":\"{{ value_json.powerConsumption }}\",""\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(topic_buf, "homeassistant/sensor/%s/startupTime/config", str_mac);
|
||||||
|
sprintf(send_buf,
|
||||||
|
"{\"name\":\"运行时间\","
|
||||||
|
"\"uniq_id\":\"tc1_%s_sut\","
|
||||||
|
"\"object_id\":\"tc1_%s_sut\","
|
||||||
|
"\"state_topic\":\"homeassistant/sensor/%s/startupTime/state\","
|
||||||
|
"\"icon\":\"mdi:clock-time-three-outline\","
|
||||||
|
"\"entity_category\":\"diagnostic\","
|
||||||
|
"\"value_template\":\"{{ value_json.startupTime }}\",""\"device\":{"
|
||||||
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
|
"\"name\":\"%s\","
|
||||||
|
"\"model\":\"TC1\","
|
||||||
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
|
str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/config", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_powerConsumptionToday\","
|
"{\"name\":\"今日耗电量\","
|
||||||
"\"uniq_id\":\"%s_pc_today\","
|
"\"uniq_id\":\"tc1_%s_pc_today\","
|
||||||
|
"\"object_id\":\"tc1_%s_pc_today\","
|
||||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionToday/state\","
|
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionToday/state\","
|
||||||
"\"unit_of_measurement\":\"kWh\","
|
"\"unit_of_measurement\":\"kWh\","
|
||||||
"\"icon\":\"mdi:fence-electric\","
|
"\"icon\":\"mdi:fence-electric\","
|
||||||
"\"value_template\":\"{{ value_json.powerConsumptionToday }}\",""\"device\":{"
|
"\"value_template\":\"{{ value_json.powerConsumptionToday }}\",""\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
|
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionYesterday/config", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionYesterday/config", str_mac);
|
||||||
sprintf(send_buf,
|
sprintf(send_buf,
|
||||||
"{\"name\":\"TC1_%s_powerConsumptionYesterday\","
|
"{\"name\":\"昨日耗电量\","
|
||||||
"\"uniq_id\":\"%s_pc_yesterday\","
|
"\"uniq_id\":\"tc1_%s_pc_yesterday\","
|
||||||
|
"\"object_id\":\"tc1_%s_pc_yesterday\","
|
||||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionYesterday/state\","
|
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionYesterday/state\","
|
||||||
"\"unit_of_measurement\":\"kWh\","
|
"\"unit_of_measurement\":\"kWh\","
|
||||||
"\"icon\":\"mdi:fence-electric\","
|
"\"icon\":\"mdi:fence-electric\","
|
||||||
"\"value_template\":\"{{ value_json.powerConsumptionYesterday }}\",""\"device\":{"
|
"\"value_template\":\"{{ value_json.powerConsumptionYesterday }}\",""\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"TC1_%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf) free(send_buf);
|
if (send_buf) free(send_buf);
|
||||||
@@ -654,7 +825,7 @@ void UserMqttHassAutoPower(void) {
|
|||||||
char topic_buf[128] = {0};
|
char topic_buf[128] = {0};
|
||||||
char send_buf[128] = {0};
|
char send_buf[128] = {0};
|
||||||
|
|
||||||
void UserMqttHassPower(void) {
|
extern void UserMqttHassPower(void) {
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
|
||||||
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power / 10);
|
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power / 10);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||||
@@ -663,6 +834,21 @@ void UserMqttHassPower(void) {
|
|||||||
sprintf(send_buf, "{\"powerConsumption\":\"%.3f\"}", (17.1 * p_count) / 1000 / 36000);
|
sprintf(send_buf, "{\"powerConsumption\":\"%.3f\"}", (17.1 * p_count) / 1000 / 36000);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||||
|
|
||||||
|
//计算系统运行时间
|
||||||
|
char up_time[16] = "00:00:00";
|
||||||
|
mico_time_t past_ms = 0;
|
||||||
|
mico_time_get_time(&past_ms);
|
||||||
|
int past = past_ms / 1000;
|
||||||
|
int d = past / 3600 / 24;
|
||||||
|
int h = past / 3600 % 24;
|
||||||
|
int m = past / 60 % 60;
|
||||||
|
int s = past % 60;
|
||||||
|
sprintf(up_time, "%d - %02d:%02d:%02d", d, h, m, s);
|
||||||
|
|
||||||
|
sprintf(topic_buf, "homeassistant/sensor/%s/startupTime/state", str_mac);
|
||||||
|
sprintf(send_buf, "{\"startupTime\":\"%s\"}", up_time);
|
||||||
|
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||||
|
|
||||||
// tc1_log("p_count %ld, p_count_1_day_ago %ld ,p_count_2_days_ago %ld, result %ld",p_count,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago,((p_count-user_config->p_count_1_day_ago)<0?0:(p_count-user_config->p_count_1_day_ago)));
|
// tc1_log("p_count %ld, p_count_1_day_ago %ld ,p_count_2_days_ago %ld, result %ld",p_count,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago,((p_count-user_config->p_count_1_day_ago)<0?0:(p_count-user_config->p_count_1_day_ago)));
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/state", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/state", str_mac);
|
||||||
sprintf(send_buf, "{\"powerConsumptionToday\":\"%.3f\"}", (17.1 * ((p_count -
|
sprintf(send_buf, "{\"powerConsumptionToday\":\"%.3f\"}", (17.1 * ((p_count -
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
#define MQTT_CMD_TIMEOUT 5000 // 5s
|
#define MQTT_CMD_TIMEOUT 5000 // 5s
|
||||||
#define MQTT_YIELD_TMIE 5000 // 5s
|
#define MQTT_YIELD_TMIE 5000 // 5s
|
||||||
|
|
||||||
#define MAX_MQTT_TOPIC_SIZE (256)
|
#define MAX_MQTT_TOPIC_SIZE (512)
|
||||||
#define MAX_MQTT_DATA_SIZE (1024)
|
#define MAX_MQTT_DATA_SIZE (2048)
|
||||||
#define MAX_MQTT_SEND_QUEUE_SIZE (10)
|
#define MAX_MQTT_SEND_QUEUE_SIZE (10)
|
||||||
|
|
||||||
#define MQTT_SERVER user_config->mqtt_ip
|
#define MQTT_SERVER user_config->mqtt_ip
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#define MQTT_LED_ENABLED user_config->power_led_enabled
|
#define MQTT_LED_ENABLED user_config->power_led_enabled
|
||||||
|
|
||||||
extern OSStatus UserMqttInit(void);
|
extern OSStatus UserMqttInit(void);
|
||||||
|
extern OSStatus UserMqttDeInit(void);
|
||||||
|
|
||||||
extern OSStatus UserMqttSend(char *arg);
|
extern OSStatus UserMqttSend(char *arg);
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ extern OSStatus UserMqttSendSocketState(char socket_id);
|
|||||||
|
|
||||||
extern OSStatus UserMqttSendLedState(void);
|
extern OSStatus UserMqttSendLedState(void);
|
||||||
|
|
||||||
|
extern OSStatus UserMqttSendChildLockState(void);
|
||||||
|
|
||||||
extern OSStatus UserMqttSendTotalSocketState(void);
|
extern OSStatus UserMqttSendTotalSocketState(void);
|
||||||
|
|
||||||
extern void UserMqttHassAuto(char socket_id);
|
extern void UserMqttHassAuto(char socket_id);
|
||||||
@@ -41,6 +44,12 @@ extern void UserMqttHassAutoPower(void);
|
|||||||
|
|
||||||
extern void UserMqttHassAutoLed(void);
|
extern void UserMqttHassAutoLed(void);
|
||||||
|
|
||||||
|
extern void UserMqttHassAutoChildLock(void);
|
||||||
|
|
||||||
extern void UserMqttHassAutoTotalSocket(void);
|
extern void UserMqttHassAutoTotalSocket(void);
|
||||||
|
|
||||||
|
extern void registerMqttEvents(void);
|
||||||
|
|
||||||
|
extern void UserMqttHassAutoRebootButton(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
|
|||||||
InitMd5(&md5);
|
InitMd5(&md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
httpHeader = HTTPHeaderCreateWithCallback(1024, OnReceivedData, NULL, NULL);
|
httpHeader = HTTPHeaderCreateWithCallback(512, OnReceivedData, NULL, NULL);
|
||||||
require_action(httpHeader, DELETE, OtaServerProgressSet(OTA_FAIL));
|
require_action(httpHeader, DELETE, OtaServerProgressSet(OTA_FAIL));
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#define __ota_server_H
|
#define __ota_server_H
|
||||||
|
|
||||||
#define OTA_DEBUG (1)
|
#define OTA_DEBUG (1)
|
||||||
#define OTA_USE_HTTPS (0)
|
#define OTA_USE_HTTPS (1)
|
||||||
|
|
||||||
#define OTA_MD5_LENTH 32
|
#define OTA_MD5_LENTH 32
|
||||||
#define OTA_SEND_HEAD_SIZE 256
|
#define OTA_SEND_HEAD_SIZE 256
|
||||||
@@ -109,34 +109,34 @@ typedef struct _ota_server_context_t{
|
|||||||
* @return kNoErr : on success.
|
* @return kNoErr : on success.
|
||||||
* @return kGeneralErr : if an error occurred
|
* @return kGeneralErr : if an error occurred
|
||||||
*/
|
*/
|
||||||
OSStatus OtaServerStart(char *url, char *md5, ota_server_cb_fn call_back);
|
OSStatus ota_server_start( char *url, char *md5, ota_server_cb_fn call_back );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Get OTA server state
|
/** @brief Get OTA server state
|
||||||
*
|
*
|
||||||
* @return OTA_CONTROL_E : state
|
* @return OTA_CONTROL_E : state
|
||||||
*/
|
*/
|
||||||
OTA_CONTROL_E OtaServerStateGet(void);
|
OTA_CONTROL_E ota_server_state_get( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Pause OTA server daemons
|
/** @brief Pause OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerPause(void);
|
void ota_server_pause( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Continue OTA server daemons
|
/** @brief Continue OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerContinue(void);
|
void ota_server_continue( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Stop OTA server daemons
|
/** @brief Stop OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerStop(void);
|
void ota_server_stop( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -36,6 +36,6 @@ void UserOtaStart(char *url, char *md5)
|
|||||||
{
|
{
|
||||||
ota_progress = 0;
|
ota_progress = 0;
|
||||||
ota_log("ready to ota:%s",url);
|
ota_log("ready to ota:%s",url);
|
||||||
OtaServerStart(url, md5, OtaServerStatusHandler);
|
ota_server_start(url, md5, OtaServerStatusHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ OSStatus UserRtcInit(void)
|
|||||||
/* start rtc client */
|
/* start rtc client */
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
||||||
(mico_thread_function_t) RtcThread,
|
(mico_thread_function_t) RtcThread,
|
||||||
0x1000, 0);
|
0x800, 0);
|
||||||
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
|
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);
|
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
#include"main.h"
|
#include"main.h"
|
||||||
#include"user_gpio.h"
|
#include"user_gpio.h"
|
||||||
|
#include "mqtt_server/user_mqtt_client.h"
|
||||||
#include"timed_task/timed_task.h"
|
#include"timed_task/timed_task.h"
|
||||||
#include"http_server/web_log.h"
|
#include"http_server/web_log.h"
|
||||||
|
#include "user_wifi.h"
|
||||||
|
|
||||||
int day_sec = 86400;
|
int day_sec = 86400;
|
||||||
|
|
||||||
@@ -142,9 +144,61 @@ bool DelTask(int time)
|
|||||||
|
|
||||||
void ProcessTask()
|
void ProcessTask()
|
||||||
{
|
{
|
||||||
task_log("process task time[%ld] socket_idx[%d] on[%d]",
|
task_log("process task time[%ld] operation[%s] on[%d]",
|
||||||
user_config->task_top->prs_time, user_config->task_top->socket_idx, user_config->task_top->on);
|
user_config->task_top->prs_time, get_func_name(user_config->task_top->operation), user_config->task_top->on);
|
||||||
UserRelaySet(user_config->task_top->socket_idx, 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();
|
DelFirstTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +218,8 @@ char* GetTaskStr()
|
|||||||
tm_info = localtime(&prs_time);
|
tm_info = localtime(&prs_time);
|
||||||
strftime(buffer, 26, "%m-%d %H:%M", tm_info);
|
strftime(buffer, 26, "%m-%d %H:%M", tm_info);
|
||||||
|
|
||||||
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','socket_idx':%d,'on':%d,'weekday':%d},",
|
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','operation':%d,'on':%d,'weekday':%d},",
|
||||||
tmp_tsk->prs_time, buffer, tmp_tsk->socket_idx+1, tmp_tsk->on, tmp_tsk->weekday);
|
tmp_tsk->prs_time, buffer, tmp_tsk->operation, tmp_tsk->on, tmp_tsk->weekday);
|
||||||
tmp_str += strlen(tmp_str);
|
tmp_str += strlen(tmp_str);
|
||||||
tmp_tsk = tmp_tsk->next;
|
tmp_tsk = tmp_tsk->next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ struct TimedTask
|
|||||||
{
|
{
|
||||||
bool on_use; //正在使用
|
bool on_use; //正在使用
|
||||||
time_t prs_time; //被执行的格林尼治时间戳
|
time_t prs_time; //被执行的格林尼治时间戳
|
||||||
int socket_idx; //要控制的插孔
|
int operation; //要进行的操作
|
||||||
int on; //开或者关
|
int on; //开或者关,或者其他操作
|
||||||
int weekday; //星期重复 0代表不重复 8代表每日重复
|
int weekday; //星期重复 0代表不重复 8代表每日重复
|
||||||
pTimedTask next; //下一个任务(按之间排序)
|
pTimedTask next; //下一个任务(按之间排序)
|
||||||
};
|
};
|
||||||
|
|||||||
414
TC1/user_gpio.c
414
TC1/user_gpio.c
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
|
#include "user_wifi.h"
|
||||||
#include "mqtt_server/user_mqtt_client.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 };
|
mico_gpio_t relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
|
||||||
char socket_status[32] = { 0 };
|
char socket_status[32] = {0};
|
||||||
|
char btn_click_config[500] = {0};
|
||||||
|
|
||||||
void UserLedSet(char x)
|
void UserLedSet(char x) {
|
||||||
{
|
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
MicoGpioOutputTrigger(Led);
|
MicoGpioOutputTrigger(Led);
|
||||||
else if (x)
|
else if (x)
|
||||||
@@ -17,21 +18,70 @@ void UserLedSet(char x)
|
|||||||
MicoGpioOutputLow(Led);
|
MicoGpioOutputLow(Led);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RelayOut(void)
|
bool RelayOut(void) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++) {
|
||||||
{
|
if (user_config->socket_status[i] != 0) {
|
||||||
if (user_config->socket_status[i] != 0)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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",
|
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
|
||||||
user_config->socket_status[0],
|
user_config->socket_status[0],
|
||||||
user_config->socket_status[1],
|
user_config->socket_status[1],
|
||||||
@@ -42,18 +92,37 @@ char* GetSocketStatus()
|
|||||||
return socket_status;
|
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,",
|
sscanf(socket_status, "%d,%d,%d,%d,%d,%d,",
|
||||||
(int*)&user_config->socket_status[0],
|
(int *) &user_config->socket_status[0],
|
||||||
(int*)&user_config->socket_status[1],
|
(int *) &user_config->socket_status[1],
|
||||||
(int*)&user_config->socket_status[2],
|
(int *) &user_config->socket_status[2],
|
||||||
(int*)&user_config->socket_status[3],
|
(int *) &user_config->socket_status[3],
|
||||||
(int*)&user_config->socket_status[4],
|
(int *) &user_config->socket_status[4],
|
||||||
(int*)&user_config->socket_status[5]);
|
(int *) &user_config->socket_status[5]);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++) {
|
||||||
{
|
|
||||||
UserRelaySet(i, user_config->socket_status[i]);
|
UserRelaySet(i, user_config->socket_status[i]);
|
||||||
UserMqttSendSocketState(i);
|
UserMqttSendSocketState(i);
|
||||||
}
|
}
|
||||||
@@ -64,29 +133,27 @@ void SetSocketStatus(char* socket_status)
|
|||||||
/*UserRelaySet
|
/*UserRelaySet
|
||||||
* 设置继电器开关
|
* 设置继电器开关
|
||||||
* i:编号 0-5
|
* 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 (i < 0 || i >= SOCKET_NUM) return;
|
||||||
|
|
||||||
if (on == Relay_ON)
|
if (on == Relay_ON) {
|
||||||
{
|
|
||||||
MicoGpioOutputHigh(relay[i]);
|
MicoGpioOutputHigh(relay[i]);
|
||||||
}
|
} else if (on == Relay_OFF) {
|
||||||
else
|
MicoGpioOutputLow(relay[i]);
|
||||||
{
|
} else if (on == Relay_TOGGLE) {
|
||||||
|
if (user_config->socket_status[i] == Relay_OFF) {
|
||||||
|
MicoGpioOutputHigh(relay[i]);
|
||||||
|
} else {
|
||||||
MicoGpioOutputLow(relay[i]);
|
MicoGpioOutputLow(relay[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_config->socket_status[i] = on;
|
|
||||||
|
|
||||||
if (RelayOut()&&user_config->power_led_enabled)
|
|
||||||
{
|
|
||||||
UserLedSet(1);
|
|
||||||
}
|
}
|
||||||
else
|
user_config->socket_status[i] = on >= 0 ? on : (user_config->socket_status[i] == 0 ? 1 : 0);
|
||||||
{
|
|
||||||
|
if (RelayOut() && user_config->power_led_enabled) {
|
||||||
|
UserLedSet(1);
|
||||||
|
} else {
|
||||||
UserLedSet(0);
|
UserLedSet(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,112 +163,229 @@ void UserRelaySet(unsigned char i, unsigned char on)
|
|||||||
* y: 0:全部关 1:全部开
|
* y: 0:全部关 1:全部开
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void UserRelaySetAll(char y)
|
void UserRelaySetAll(char y) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++)
|
||||||
UserRelaySet(i, y);
|
UserRelaySet(i, y);
|
||||||
}
|
}
|
||||||
|
static void KeyEventHandler(int num, boolean longPress) {
|
||||||
static void KeyLongPress(void)
|
key_log("WARNGIN:Power key %s %d %s", !longPress ? "quick clicked" : "longPressed", num,
|
||||||
{
|
num > 1 ? (longPress ? "seconds" : "times") : (longPress ? "second" : "time"));
|
||||||
// key_log("KeyLongPress");
|
if (num > 30 || num <= 0)
|
||||||
// UserLedSet(1);
|
return;
|
||||||
// UserMqttSend("mqtt test");
|
int function = !longPress ? get_short_func(user_config->user[num]) : get_long_func(
|
||||||
}
|
user_config->user[num]);
|
||||||
|
boolean showLog= childLockEnabled==0;
|
||||||
static void KeyLong10sPress(void)
|
switch (function) {
|
||||||
{
|
case SWITCH_ALL_SOCKETS:
|
||||||
key_log("WARNGIN: user params restored!");
|
if (childLockEnabled)
|
||||||
appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
break;
|
||||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
if (RelayOut()) {
|
||||||
mico_system_context_update(mico_system_context_get());
|
|
||||||
}
|
|
||||||
static void KeyShortPress(void)
|
|
||||||
{
|
|
||||||
char i;
|
|
||||||
|
|
||||||
if (RelayOut())
|
|
||||||
{
|
|
||||||
UserRelaySetAll(0);
|
UserRelaySetAll(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
UserRelaySetAll(1);
|
UserRelaySetAll(1);
|
||||||
}
|
}
|
||||||
|
mico_system_context_update(sys_config);
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (int i = 0; i < SOCKET_NUM; i++) {
|
||||||
{
|
|
||||||
UserMqttSendSocketState(i);
|
UserMqttSendSocketState(i);
|
||||||
}
|
}
|
||||||
UserMqttSendTotalSocketState();
|
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 !");
|
||||||
}
|
}
|
||||||
mico_timer_t user_key_timer;
|
|
||||||
uint16_t key_time = 0;
|
|
||||||
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
|
|
||||||
|
|
||||||
static void KeyTimeoutHandler(void* arg)
|
mico_timer_t user_key_timer;
|
||||||
|
// 全局静态变量声明
|
||||||
|
static uint8_t click_count = 0;
|
||||||
|
static mico_timer_t click_end_timer;
|
||||||
|
uint16_t key_time = 0;
|
||||||
|
|
||||||
|
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 char key_trigger, key_continue;
|
||||||
//按键扫描程序
|
static uint8_t key_time = 0;
|
||||||
|
|
||||||
char tmp = ~(0xfe | MicoGpioInputGet(Button));
|
char tmp = ~(0xfe | MicoGpioInputGet(Button));
|
||||||
key_trigger = tmp & (tmp ^ key_continue);
|
key_trigger = tmp & (tmp ^ key_continue);
|
||||||
key_continue = tmp;
|
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)
|
if (key_trigger != 0)
|
||||||
{
|
|
||||||
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_time = 0;
|
||||||
key_log("button short pressed:%d",key_time);
|
|
||||||
KeyShortPress();
|
if (key_continue != 0) {
|
||||||
}
|
key_time++;
|
||||||
else if (key_time > 100)
|
// if (key_time > BUTTON_LONG_PRESS_TIME) {
|
||||||
{
|
// if (key_time == 50) {
|
||||||
MicoSystemReboot();
|
// 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_timer(300ms)
|
||||||
|
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);
|
mico_rtos_stop_timer(&user_key_timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeyFallingIrqHandler(void* arg)
|
static void KeyFallingIrqHandler(void *arg) {
|
||||||
{
|
|
||||||
mico_rtos_start_timer(&user_key_timer);
|
mico_rtos_start_timer(&user_key_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyInit(void)
|
void KeyInit(void) {
|
||||||
{
|
|
||||||
MicoGpioInitialize(Button, INPUT_PULL_UP);
|
MicoGpioInitialize(Button, INPUT_PULL_UP);
|
||||||
mico_rtos_init_timer(&user_key_timer, 100, KeyTimeoutHandler, NULL);
|
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);
|
MicoGpioEnableIRQ(Button, IRQ_TRIGGER_FALLING_EDGE, KeyFallingIrqHandler, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,35 @@
|
|||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "micokit_ext.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];
|
extern char socket_status[32];
|
||||||
|
|
||||||
void UserLedSet(char x);
|
void UserLedSet(char x);
|
||||||
void KeyInit(void);
|
void KeyInit(void);
|
||||||
void UserRelaySet(unsigned char x,unsigned char y);
|
void UserRelaySet(unsigned char x, char y);
|
||||||
void UserRelaySetAll(char y);
|
void UserRelaySetAll(char y);
|
||||||
bool RelayOut(void);
|
bool RelayOut(void);
|
||||||
char* GetSocketStatus();
|
char* GetSocketStatus();
|
||||||
|
char* GetButtonClickConfig();
|
||||||
void SetSocketStatus(char* socket_status);
|
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
|
#endif
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "mico_socket.h"
|
#include "mico_socket.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
#include "mqtt_server/user_mqtt_client.h"
|
||||||
|
|
||||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||||
|
|
||||||
@@ -122,6 +123,9 @@ static void WifiLedTimerCallback(void* arg)
|
|||||||
UserLedSet(-1);
|
UserLedSet(-1);
|
||||||
break;
|
break;
|
||||||
case WIFI_STATE_CONNECTED:
|
case WIFI_STATE_CONNECTED:
|
||||||
|
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||||
|
UserMqttInit();
|
||||||
|
}
|
||||||
UserLedSet(0);
|
UserLedSet(0);
|
||||||
mico_rtos_stop_timer(&wifi_led_timer);
|
mico_rtos_stop_timer(&wifi_led_timer);
|
||||||
if (RelayOut()&&user_config->power_led_enabled)
|
if (RelayOut()&&user_config->power_led_enabled)
|
||||||
|
|||||||
20
build.sh
20
build.sh
@@ -1,11 +1,27 @@
|
|||||||
|
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
|
cd ./TC1/http_server
|
||||||
|
|
||||||
python ./test.py > web_data.c
|
python ./test.py > web_data.c
|
||||||
|
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
mico make clean
|
|
||||||
|
|
||||||
mico make TC1@MK3031@moc total
|
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.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
BIN
doc/IMG_0862.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 396 KiB |
BIN
doc/IMG_0863.png
Normal file
BIN
doc/IMG_0863.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 286 KiB |
BIN
doc/IMG_0887.png
Normal file
BIN
doc/IMG_0887.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 KiB |
BIN
doc/IMG_0888.png
Normal file
BIN
doc/IMG_0888.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 265 KiB |
4
mico-os/.gitignore
vendored
Normal file
4
mico-os/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
MiCoder/compiler
|
||||||
|
Projects
|
||||||
|
MiCoder
|
||||||
|
tools_root
|
||||||
@@ -39,17 +39,11 @@ OSStatus system_discovery_init( system_context_t * const inContext )
|
|||||||
init.service_name = "_easylink._tcp.local.";
|
init.service_name = "_easylink._tcp.local.";
|
||||||
|
|
||||||
/* name#xxxxxx.local. */
|
/* name#xxxxxx.local. */
|
||||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
|
snprintf( temp_txt, 100, "%s.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] );
|
|
||||||
init.host_name = (char*)__strdup(temp_txt);
|
init.host_name = (char*)__strdup(temp_txt);
|
||||||
|
|
||||||
/* name#xxxxxx. */
|
/* name#xxxxxx. */
|
||||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
|
snprintf( temp_txt, 100, "%s", 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] );
|
|
||||||
init.instance_name = (char*)__strdup(temp_txt);
|
init.instance_name = (char*)__strdup(temp_txt);
|
||||||
|
|
||||||
#ifndef MICO_LOCAL_SERVER_PORT
|
#ifndef MICO_LOCAL_SERVER_PORT
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ httpd_state_t httpd_state;
|
|||||||
|
|
||||||
static mico_thread_t httpd_main_thread;
|
static mico_thread_t httpd_main_thread;
|
||||||
|
|
||||||
#define http_server_thread_stack_size 0x2000
|
// 0x8000 不行
|
||||||
|
#define http_server_thread_stack_size 0x6000
|
||||||
|
|
||||||
/* Why HTTPD_MAX_MESSAGE + 2?
|
/* Why HTTPD_MAX_MESSAGE + 2?
|
||||||
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.
|
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.
|
||||||
|
|||||||
@@ -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_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
|
/** @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
|
* @note This function is an extension to \ref httpd_get_data. Additionally this
|
||||||
|
|||||||
@@ -135,12 +135,24 @@ int httpd_send_chunk(int conn, const char *buf, int len)
|
|||||||
int httpd_send(int conn, const char *buf, int len)
|
int httpd_send(int conn, const char *buf, int len)
|
||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
|
struct timeval t;
|
||||||
|
fd_set writefds;
|
||||||
|
|
||||||
|
t.tv_sec = 0;
|
||||||
|
t.tv_usec = 200*1000;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#ifdef CONFIG_ENABLE_HTTPS
|
#ifdef CONFIG_ENABLE_HTTPS
|
||||||
if (httpd_is_https_active())
|
if (httpd_is_https_active())
|
||||||
num = tls_send(httpd_tls_handle, buf, len);
|
num = tls_send(httpd_tls_handle, buf, len);
|
||||||
else
|
else
|
||||||
#endif /* ENABLE_HTTPS */
|
#endif /* ENABLE_HTTPS */
|
||||||
|
FD_ZERO( &writefds );
|
||||||
|
FD_SET( conn, &writefds );
|
||||||
|
|
||||||
|
select( conn + 1, NULL, &writefds, NULL, &t );
|
||||||
|
if( FD_ISSET( conn, &writefds) )
|
||||||
|
{
|
||||||
num = send(conn, buf, len, 0);
|
num = send(conn, buf, len, 0);
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
httpd_d("send() failed: %d" ,conn);
|
httpd_d("send() failed: %d" ,conn);
|
||||||
@@ -148,6 +160,7 @@ int httpd_send(int conn, const char *buf, int len)
|
|||||||
}
|
}
|
||||||
len -= num;
|
len -= num;
|
||||||
buf += num;
|
buf += num;
|
||||||
|
}
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
|
|
||||||
|
|
||||||
@@ -156,12 +169,29 @@ int httpd_send(int conn, const char *buf, int len)
|
|||||||
|
|
||||||
int httpd_recv(int fd, void *buf, size_t n, int flags)
|
int httpd_recv(int fd, void *buf, size_t n, int flags)
|
||||||
{
|
{
|
||||||
|
int len = 0;
|
||||||
|
struct timeval t;
|
||||||
|
fd_set readfds;
|
||||||
|
|
||||||
|
FD_ZERO( &readfds );
|
||||||
|
FD_SET( fd, &readfds );
|
||||||
|
|
||||||
|
t.tv_sec = 0;
|
||||||
|
t.tv_usec = 200*1000;
|
||||||
|
|
||||||
#ifdef CONFIG_ENABLE_HTTPS
|
#ifdef CONFIG_ENABLE_HTTPS
|
||||||
if (httpd_is_https_active())
|
if (httpd_is_https_active())
|
||||||
return tls_recv(httpd_tls_handle, buf, n);
|
return tls_recv(httpd_tls_handle, buf, n);
|
||||||
else
|
else
|
||||||
#endif /* ENABLE_HTTPS */
|
#endif /* ENABLE_HTTPS */
|
||||||
return recv(fd, buf, n, flags);
|
return recv(fd, buf, n, flags);
|
||||||
|
select( fd + 1, &readfds, NULL, NULL, &t );
|
||||||
|
|
||||||
|
if( FD_ISSET( fd, &readfds) )
|
||||||
|
{
|
||||||
|
len = recv( fd, buf, n, flags );
|
||||||
|
}
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int httpd_send_hdr_from_code(int sock, int stat_code,
|
int httpd_send_hdr_from_code(int sock, int stat_code,
|
||||||
|
|||||||
@@ -543,6 +543,52 @@ out:
|
|||||||
return req->remaining_bytes;
|
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)
|
static int get_matching_chars(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
int match = 0;
|
int match = 0;
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ static OSStatus ota_server_connect( struct sockaddr_in *addr, socklen_t addrlen
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ static void ota_server_thread( mico_thread_arg_t arg )
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
DELETE:
|
DELETE:
|
||||||
HTTPHeaderDestory( &httpHeader );
|
HTTPHeaderDestory( &httpHeader );
|
||||||
ota_server_socket_close( );
|
ota_server_socket_close( );
|
||||||
if( ota_server_context != NULL ){
|
if( ota_server_context != NULL ){
|
||||||
@@ -421,7 +421,7 @@ static OSStatus ota_server_set_url( char *url )
|
|||||||
strcpy( ota_server_context->download_url.url, pos );
|
strcpy( ota_server_context->download_url.url, pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
url_free( url_t );
|
url_free( url_t );
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -461,7 +461,7 @@ OSStatus ota_server_start( char *url, char *md5, ota_server_cb_fn call_back )
|
|||||||
ota_server_context->ota_server_cb = call_back;
|
ota_server_context->ota_server_cb = call_back;
|
||||||
|
|
||||||
err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY, "OTA", ota_server_thread, OTA_SERVER_THREAD_STACK_SIZE, 0 );
|
err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY, "OTA", ota_server_thread, OTA_SERVER_THREAD_STACK_SIZE, 0 );
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ int SocketReadHTTPHeader( int inSock, HTTPHeader_t *inHeader )
|
|||||||
else
|
else
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,8 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
|
|
||||||
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
||||||
else { err = kConnectionErr; goto exit; }
|
else { err = kConnectionErr; goto exit; }
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, inHeader->extraDataLen - readResult, (uint8_t *)inHeader->extraDataPtr, readResult, inHeader->userContext);
|
err = (inHeader->onReceivedDataCallback)(inHeader, inHeader->extraDataLen - readResult, (uint8_t *)inHeader->extraDataPtr, readResult, inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
@@ -185,10 +186,11 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
*(inHeader->extraDataPtr + inHeader->contentLength + 1 ) == '\n',
|
*(inHeader->extraDataPtr + inHeader->contentLength + 1 ) == '\n',
|
||||||
exit, err = kMalformedErr);
|
exit, err = kMalformedErr);
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->contentLength,
|
inHeader->contentLength,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos+=inHeader->contentLength;
|
pos+=inHeader->contentLength;
|
||||||
|
|
||||||
/* Move next chunk to chunked data buffer header point */
|
/* Move next chunk to chunked data buffer header point */
|
||||||
@@ -204,10 +206,11 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
require_action( *(inHeader->chunkedDataBufferPtr + inHeader->extraDataLen - 1) == '\r' ,
|
require_action( *(inHeader->chunkedDataBufferPtr + inHeader->extraDataLen - 1) == '\r' ,
|
||||||
exit, err = kMalformedErr);
|
exit, err = kMalformedErr);
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->extraDataLen - chunckheaderLen-1,
|
inHeader->extraDataLen - chunckheaderLen-1,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos+=inHeader->extraDataLen - chunckheaderLen-1;
|
pos+=inHeader->extraDataLen - chunckheaderLen-1;
|
||||||
selectResult = select( inSock + 1, &readSet, NULL, NULL, NULL );
|
selectResult = select( inSock + 1, &readSet, NULL, NULL, NULL );
|
||||||
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
||||||
@@ -222,10 +225,11 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/* Callback , read , callback , read CRLF */
|
/* Callback , read , callback , read CRLF */
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->extraDataLen - chunckheaderLen,
|
inHeader->extraDataLen - chunckheaderLen,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos += inHeader->extraDataLen - chunckheaderLen;
|
pos += inHeader->extraDataLen - chunckheaderLen;
|
||||||
|
|
||||||
while ( inHeader->extraDataLen < inHeader->contentLength + chunckheaderLen ){
|
while ( inHeader->extraDataLen < inHeader->contentLength + chunckheaderLen ){
|
||||||
@@ -244,10 +248,11 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
||||||
else { err = kConnectionErr; goto exit; }
|
else { err = kConnectionErr; goto exit; }
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
readResult,
|
readResult,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos += readResult;
|
pos += readResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +322,7 @@ OSStatus SocketReadHTTPBody( int inSock, HTTPHeader_t *inHeader )
|
|||||||
}
|
}
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if(err != kNoErr) inHeader->len = 0;
|
if(err != kNoErr) inHeader->len = 0;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -373,7 +378,8 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
|
|
||||||
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
||||||
else { err = kConnectionErr; goto exit; }
|
else { err = kConnectionErr; goto exit; }
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, inHeader->extraDataLen - readResult, (uint8_t *)inHeader->extraDataPtr, readResult, inHeader->userContext);
|
err = (inHeader->onReceivedDataCallback)(inHeader, inHeader->extraDataLen - readResult, (uint8_t *)inHeader->extraDataPtr, readResult, inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
@@ -386,10 +392,11 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
*(inHeader->extraDataPtr + inHeader->contentLength + 1 ) == '\n',
|
*(inHeader->extraDataPtr + inHeader->contentLength + 1 ) == '\n',
|
||||||
exit, err = kMalformedErr);
|
exit, err = kMalformedErr);
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->contentLength,
|
inHeader->contentLength,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos+=inHeader->contentLength;
|
pos+=inHeader->contentLength;
|
||||||
|
|
||||||
/* Move next chunk to chunked data buffer header point */
|
/* Move next chunk to chunked data buffer header point */
|
||||||
@@ -405,10 +412,11 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
require_action( *(inHeader->chunkedDataBufferPtr + inHeader->extraDataLen - 1) == '\r' ,
|
require_action( *(inHeader->chunkedDataBufferPtr + inHeader->extraDataLen - 1) == '\r' ,
|
||||||
exit, err = kMalformedErr);
|
exit, err = kMalformedErr);
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->extraDataLen - chunckheaderLen-1,
|
inHeader->extraDataLen - chunckheaderLen-1,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos+=inHeader->extraDataLen - chunckheaderLen-1;
|
pos+=inHeader->extraDataLen - chunckheaderLen-1;
|
||||||
selectResult = select( inSock + 1, &readSet, NULL, NULL, NULL );
|
selectResult = select( inSock + 1, &readSet, NULL, NULL, NULL );
|
||||||
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
||||||
@@ -423,10 +431,11 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/* Callback , read , callback , read CRLF */
|
/* Callback , read , callback , read CRLF */
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
inHeader->extraDataLen - chunckheaderLen,
|
inHeader->extraDataLen - chunckheaderLen,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos += inHeader->extraDataLen - chunckheaderLen;
|
pos += inHeader->extraDataLen - chunckheaderLen;
|
||||||
|
|
||||||
while ( inHeader->extraDataLen < inHeader->contentLength + chunckheaderLen ){
|
while ( inHeader->extraDataLen < inHeader->contentLength + chunckheaderLen ){
|
||||||
@@ -445,10 +454,11 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
if( readResult > 0 ) inHeader->extraDataLen += readResult;
|
||||||
else { err = kConnectionErr; goto exit; }
|
else { err = kConnectionErr; goto exit; }
|
||||||
|
|
||||||
(inHeader->onReceivedDataCallback)(inHeader, pos,
|
err = (inHeader->onReceivedDataCallback)(inHeader, pos,
|
||||||
(uint8_t *)inHeader->extraDataPtr,
|
(uint8_t *)inHeader->extraDataPtr,
|
||||||
readResult,
|
readResult,
|
||||||
inHeader->userContext);
|
inHeader->userContext);
|
||||||
|
if( err != kNoErr ) goto exit;
|
||||||
pos += readResult;
|
pos += readResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,8 +502,10 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
|
|
||||||
while ( inHeader->extraDataLen < inHeader->contentLength )
|
while ( inHeader->extraDataLen < inHeader->contentLength )
|
||||||
{
|
{
|
||||||
|
if ( !ssl_pending(ssl) ) {
|
||||||
selectResult = select( inSock + 1, &readSet, NULL, NULL, (struct timeval *)&t );
|
selectResult = select( inSock + 1, &readSet, NULL, NULL, (struct timeval *)&t );
|
||||||
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
require_action( selectResult >= 1, exit, err = kNotReadableErr );
|
||||||
|
}
|
||||||
|
|
||||||
if(inHeader->isCallbackSupported == true){
|
if(inHeader->isCallbackSupported == true){
|
||||||
/* We has extra data, and we give these data to application by onReceivedDataCallback function */
|
/* We has extra data, and we give these data to application by onReceivedDataCallback function */
|
||||||
@@ -518,7 +530,7 @@ OSStatus SocketReadHTTPSBody( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
}
|
}
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if(err != kNoErr) inHeader->len = 0;
|
if(err != kNoErr) inHeader->len = 0;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -594,7 +606,7 @@ int SocketReadHTTPSHeader( mico_ssl_t ssl, HTTPHeader_t *inHeader )
|
|||||||
else
|
else
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -773,7 +785,7 @@ OSStatus HTTPHeaderParse( HTTPHeader_t *ioHeader )
|
|||||||
|
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,7 +947,7 @@ int HTTPScanFHeaderValue( const char *inHeaderPtr, size_t inHeaderLen, const cha
|
|||||||
n = VSNScanF( valuePtr, valueLen, inFormat, args );
|
n = VSNScanF( valuePtr, valueLen, inFormat, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return( n );
|
return( n );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -981,7 +993,7 @@ HTTPHeader_t * HTTPHeaderCreateWithCallback( size_t bufLen, onReceivedDataCallba
|
|||||||
httpHeader->onReceivedDataCallback = inRecvFunc;
|
httpHeader->onReceivedDataCallback = inRecvFunc;
|
||||||
httpHeader->onClearCallback = onClearFunc;
|
httpHeader->onClearCallback = onClearFunc;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if(err != kNoErr && httpHeader != NULL){ //httpHeader->buf cannot be created
|
if(err != kNoErr && httpHeader != NULL){ //httpHeader->buf cannot be created
|
||||||
free(httpHeader);
|
free(httpHeader);
|
||||||
}
|
}
|
||||||
@@ -1058,7 +1070,7 @@ OSStatus CreateSimpleHTTPOKMessage( uint8_t **outMessage, size_t *outMessageSize
|
|||||||
|
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1093,7 +1105,7 @@ OSStatus CreateSimpleHTTPMessage( const char *contentType, uint8_t *inData, size
|
|||||||
memcpy( endOfHTTPHeader, inData, inDataLen );
|
memcpy( endOfHTTPHeader, inData, inDataLen );
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1119,7 +1131,7 @@ OSStatus CreateSimpleHTTPMessageNoCopy( const char *contentType, size_t inDataLe
|
|||||||
*outMessageSize = strlen( (char*)*outMessage );
|
*outMessageSize = strlen( (char*)*outMessage );
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1172,7 +1184,7 @@ OSStatus CreateHTTPRespondMessageNoCopy( int status, const char *contentType, si
|
|||||||
*outMessageSize = strlen( (char*)*outMessage );
|
*outMessageSize = strlen( (char*)*outMessage );
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1205,7 +1217,7 @@ OSStatus CreateHTTPMessage( const char *methold, const char *url, const char *co
|
|||||||
memcpy( endOfHTTPHeader, inData, inDataLen );
|
memcpy( endOfHTTPHeader, inData, inDataLen );
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1243,7 +1255,7 @@ OSStatus CreateHTTPMessageWithHost( const char *methold, const char *url,
|
|||||||
memcpy( endOfHTTPHeader, inData, inDataLen );
|
memcpy( endOfHTTPHeader, inData, inDataLen );
|
||||||
err = kNoErr;
|
err = kNoErr;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1264,4 +1276,3 @@ void PrintHTTPHeader( HTTPHeader_t *inHeader )
|
|||||||
http_utils_log("Content length: %ld", (uint32_t)(inHeader->contentLength));
|
http_utils_log("Content length: %ld", (uint32_t)(inHeader->contentLength));
|
||||||
http_utils_log("Persistent: %s", YesOrNo( inHeader->persistent ));
|
http_utils_log("Persistent: %s", YesOrNo( inHeader->persistent ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,33 +40,35 @@
|
|||||||
#include "URLUtils.h"
|
#include "URLUtils.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#define Boolean bool
|
||||||
|
|
||||||
#define kHTTPPostMethod "POST"
|
#define kHTTPPostMethod "POST"
|
||||||
|
|
||||||
// Status-Code =
|
// Status-Code =
|
||||||
// "100" ; Section 10.1.1: Continue
|
// "100" ; Section 10.1.1: Continue
|
||||||
// | "101" ; Section 10.1.2: Switching Protocols
|
// | "101" ; Section 10.1.2: Switching Protocols
|
||||||
// | "200" ; Section 10.2.1: OK
|
// | "200" ; Section 10.2.1: OK
|
||||||
// | "201" ; Section 10.2.2: Created
|
// | "201" ; Section 10.2.2: Created
|
||||||
// | "202" ; Section 10.2.3: Accepted
|
// | "202" ; Section 10.2.3: Accepted
|
||||||
// | "203" ; Section 10.2.4: Non-Authoritative Information
|
// | "203" ; Section 10.2.4: Non-Authoritative Information
|
||||||
// | "204" ; Section 10.2.5: No Content
|
// | "204" ; Section 10.2.5: No Content
|
||||||
// | "205" ; Section 10.2.6: Reset Content
|
// | "205" ; Section 10.2.6: Reset Content
|
||||||
// | "206" ; Section 10.2.7: Partial Content
|
// | "206" ; Section 10.2.7: Partial Content
|
||||||
// | "207" ; ??? : Multi-Status
|
// | "207" ; ??? : Multi-Status
|
||||||
// | "300" ; Section 10.3.1: Multiple Choices
|
// | "300" ; Section 10.3.1: Multiple Choices
|
||||||
// | "301" ; Section 10.3.2: Moved Permanently
|
// | "301" ; Section 10.3.2: Moved Permanently
|
||||||
// | "302" ; Section 10.3.3: Found
|
// | "302" ; Section 10.3.3: Found
|
||||||
// | "303" ; Section 10.3.4: See Other
|
// | "303" ; Section 10.3.4: See Other
|
||||||
// | "304" ; Section 10.3.5: Not Modified
|
// | "304" ; Section 10.3.5: Not Modified
|
||||||
// | "305" ; Section 10.3.6: Use Proxy
|
// | "305" ; Section 10.3.6: Use Proxy
|
||||||
// | "307" ; Section 10.3.8: Temporary Redirect
|
// | "307" ; Section 10.3.8: Temporary Redirect
|
||||||
// | "400" ; Section 10.4.1: Bad Request
|
// | "400" ; Section 10.4.1: Bad Request
|
||||||
// | "401" ; Section 10.4.2: Unauthorized
|
// | "401" ; Section 10.4.2: Unauthorized
|
||||||
// | "402" ; Section 10.4.3: Payment Required
|
// | "402" ; Section 10.4.3: Payment Required
|
||||||
// | "403" ; Section 10.4.4: Forbidden
|
// | "403" ; Section 10.4.4: Forbidden
|
||||||
// | "404" ; Section 10.4.5: Not Found
|
// | "404" ; Section 10.4.5: Not Found
|
||||||
// | "405" ; Section 10.4.6: Method Not Allowed
|
// | "405" ; Section 10.4.6: Method Not Allowed
|
||||||
// | "406" ; Section 10.4.7: Not Acceptable
|
// | "406" ; Section 10.4.7: Not Acceptable
|
||||||
|
|
||||||
|
|
||||||
#define kStatusAccept 202
|
#define kStatusAccept 202
|
||||||
@@ -202,4 +204,3 @@ OSStatus CreateHTTPMessageWithHost( const char *methold, const char *url,
|
|||||||
uint8_t **outMessage, size_t *outMessageSize );
|
uint8_t **outMessage, size_t *outMessageSize );
|
||||||
|
|
||||||
#endif // __HTTPUtils_h__
|
#endif // __HTTPUtils_h__
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user