Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71a01cc63e | ||
|
|
4d2e84f027 | ||
|
|
81b5677b5f | ||
|
|
daa6909f5d | ||
|
|
7a163ec85f | ||
|
|
ac7d26eb9c | ||
|
|
531256529f | ||
|
|
2352075c58 | ||
|
|
ca8ec3c993 | ||
|
|
5f60ea3841 | ||
|
|
882f7d6784 | ||
|
|
5fccab5aff | ||
|
|
707df025b8 | ||
|
|
b7f6325dea | ||
|
|
6225906851 | ||
|
|
63dbc4a5cd | ||
|
|
6dc0968f88 | ||
|
|
6b1ca06c91 | ||
|
|
f04e18a366 | ||
|
|
b5502d0249 | ||
|
|
f79ac90eb5 | ||
|
|
40a62bf023 | ||
|
|
0ff204fd63 | ||
|
|
f46c75d405 |
@@ -3,4 +3,5 @@
|
|||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/ipch
|
.vscode/ipch
|
||||||
|
.venv
|
||||||
todo.txt
|
todo.txt
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="210mm"
|
||||||
|
height="297mm"
|
||||||
|
viewBox="0 0 210 297"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
inkscape:version="1.4 (86a8ad7, 2024-10-11)"
|
||||||
|
sodipodi:docname="nanoPSX.svg"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#505050"
|
||||||
|
bordercolor="#eeeeee"
|
||||||
|
borderopacity="1"
|
||||||
|
inkscape:showpageshadow="0"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#505050"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:zoom="2.2501035"
|
||||||
|
inkscape:cx="395.75958"
|
||||||
|
inkscape:cy="449.97931"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1137"
|
||||||
|
inkscape:window-x="-8"
|
||||||
|
inkscape:window-y="-8"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="layer1" />
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<g
|
||||||
|
inkscape:label="Ebene 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1">
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:italic;font-size:27.2145px;font-family:Pigiarniq;-inkscape-font-specification:'Pigiarniq, Italic';text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:0.371681;fill:none;fill-opacity:0;stroke:#000000;stroke-width:0.1;stroke-linecap:round"
|
||||||
|
x="46.894733"
|
||||||
|
y="125.05263"
|
||||||
|
id="text1"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan1"
|
||||||
|
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:27.2145px;font-family:Pigiarniq;-inkscape-font-specification:'Pigiarniq, Italic';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;stroke-width:0.1;fill:none"
|
||||||
|
x="46.894733"
|
||||||
|
y="125.05263">nanoPSX</tspan></text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,996 @@
|
|||||||
|
solid ascii
|
||||||
|
facet normal 1.953640e-01 -9.807308e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.802079e-04 -1.000000e+00 -6.507516e-10
|
||||||
|
outer loop
|
||||||
|
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.807296e-01 -1.953699e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802309e-04 9.546130e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802103e-04 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.808400e-01 -1.948151e-01 -3.699727e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.807306e-01 -1.953652e-01 -1.497794e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.807315e-01 -1.953605e-01 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.313134e-01 -5.558038e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.313140e-01 -5.558031e-01 -2.625587e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.948128e-01 -9.808405e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.313144e-01 -5.558025e-01 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.943541e-07 1.199650e-07 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.802079e-04 -1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.553374e-01 -8.316251e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.948269e-01 -9.808376e-01 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.948198e-01 -9.808390e-01 -2.243689e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.802079e-04 -9.999999e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -8.300002e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.553346e-01 -8.316270e-01 1.062179e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.808398e-01 -1.948163e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.557968e-01 -8.313181e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.808402e-01 -1.948140e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.922910e-08 6.398150e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 8.316317e-01 -5.553275e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 3.591652e-08 1.023813e-07 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.557982e-01 -8.313172e-01 5.370561e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.553318e-01 -8.316289e-01 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -3.064736e-11 1.093449e-07 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 8.316280e-01 -5.553332e-01 2.112395e-06
|
||||||
|
outer loop
|
||||||
|
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -8.300002e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.801910e-04 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.802309e-04 -9.536661e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -8.300002e+00
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.953699e-01 -9.807296e-01 1.873721e-06
|
||||||
|
outer loop
|
||||||
|
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.557997e-01 -8.313163e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 8.316242e-01 -5.553388e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -8.300002e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.953758e-01 -9.807284e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -8.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 7.071067e-01 1.225341e-07 -7.071068e-01
|
||||||
|
outer loop
|
||||||
|
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -4.644116e-11 1.657095e-07 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 7.071071e-01 9.072717e-08 -7.071065e-01
|
||||||
|
outer loop
|
||||||
|
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.045283e-01 9.945220e-01 -1.479396e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 3.969645e-08 1.732894e-07 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
|
||||||
|
vertex 7.611846e+00 1.594458e+00 -8.300000e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.045283e-01 9.945219e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.802708e-04 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.045283e-01 9.945220e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -8.299999e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.802101e-04 9.534234e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.803075e-04 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.048722e-07 2.082973e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -6.485803e-08 4.331049e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -3.846582e-08 5.753344e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.591929e-01 -8.290375e-01 4.293063e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.396867e-08 7.012171e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802315e-04 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 9.739661e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.802564e-04 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.802564e-04 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.802564e-04 9.999999e-01 -3.408327e-10
|
||||||
|
outer loop
|
||||||
|
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.802746e-04 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802316e-04 6.011294e-10
|
||||||
|
outer loop
|
||||||
|
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.157557e-11 7.695623e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.802361e-04 4.773700e-07
|
||||||
|
outer loop
|
||||||
|
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -8.299998e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.945013e-08 7.693617e-08 -1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 7.071064e-01 9.072726e-08 -7.071071e-01
|
||||||
|
outer loop
|
||||||
|
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
|
||||||
|
vertex 7.611846e+00 1.260118e+01 -8.299998e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.591929e-01 -8.290375e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.591929e-01 -8.290376e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -8.299998e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.316252e-01 5.553374e-01 -7.910898e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.557988e-01 8.313168e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.558053e-01 8.313125e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.558020e-01 8.313147e-01 -1.050240e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.953667e-01 9.807302e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.953681e-01 9.807300e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.953674e-01 9.807302e-01 1.875426e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802316e-04 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.801977e-04 5.344356e-10
|
||||||
|
outer loop
|
||||||
|
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.803615e-04 9.999999e-01 1.534703e-10
|
||||||
|
outer loop
|
||||||
|
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.316268e-01 5.553350e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -8.299997e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.800473e-04 9.999999e-01 1.907352e-06
|
||||||
|
outer loop
|
||||||
|
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.803615e-04 9.999999e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -8.299997e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802513e-04 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.801127e-04 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -8.299997e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.316236e-01 5.553398e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -8.299997e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 7.071068e-01 5.972228e-08 -7.071068e-01
|
||||||
|
outer loop
|
||||||
|
vertex 7.861846e+00 7.195271e+00 -8.049999e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.553346e-01 -8.316270e-01 -1.050244e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.190768e+01 -2.244003e+01 -7.800003e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.948198e-01 -9.808390e-01 2.237722e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.162481e+01 -2.255711e+01 -7.800003e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.808400e-01 -1.948151e-01 3.759400e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.219607e+01 -2.193396e+01 -7.800003e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.807306e-01 -1.953652e-01 1.497794e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.224146e+01 -2.194081e+01 -7.800003e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.953699e-01 -9.807296e-01 -1.867753e-06
|
||||||
|
outer loop
|
||||||
|
vertex 1.157977e+01 -2.255061e+01 -7.800003e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.557982e-01 -8.313172e-01 -5.251215e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.186258e+01 -2.243337e+01 -7.800003e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 8.316280e-01 -5.553332e-01 -2.124329e-06
|
||||||
|
outer loop
|
||||||
|
vertex 1.207900e+01 -2.221683e+01 -7.800003e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.802079e-04 -1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -2.251063e-02 -2.258431e+01 -7.800003e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.313140e-01 -5.558031e-01 2.625587e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.212422e+01 -2.222361e+01 -7.800003e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.802309e-04 9.536648e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.222314e+01 -9.851052e+00 -7.800002e+00
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.999999e-01 -2.802309e-04 -9.558927e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.227848e+01 1.501878e+00 -7.800001e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.800000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.802564e-04 1.000000e+00 3.408324e-10
|
||||||
|
outer loop
|
||||||
|
vertex -4.829637e-02 1.310250e+01 -7.800000e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 2.802101e-04 -9.534234e-07
|
||||||
|
outer loop
|
||||||
|
vertex 1.221460e+01 2.060253e+01 -7.799999e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.999999e-01 2.802362e-04 -4.767691e-07
|
||||||
|
outer loop
|
||||||
|
vertex -5.515032e+00 1.929718e+01 -7.799999e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.000000e+00 -2.802316e-04 -3.005649e-10
|
||||||
|
outer loop
|
||||||
|
vertex 5.414967e+00 1.930120e+01 -7.799999e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 0.000000e+00 -0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.799999e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.808400e-01 1.948146e-01 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.225840e+01 2.492544e+01 -7.799998e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.800472e-04 9.999999e-01 1.907329e-06
|
||||||
|
outer loop
|
||||||
|
vertex -8.550983e+00 2.549254e+01 -7.799998e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -0.000000e+00 1.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.813231e+00 2.549836e+01 -7.799998e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.558020e-01 8.313147e-01 1.050240e-06
|
||||||
|
outer loop
|
||||||
|
vertex -1.196659e+01 2.536243e+01 -7.799998e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.953674e-01 9.807302e-01 -1.841328e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.171913e+01 2.546501e+01 -7.799998e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -8.316252e-01 5.553374e-01 7.910898e-07
|
||||||
|
outer loop
|
||||||
|
vertex -1.215596e+01 2.517296e+01 -7.799998e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 7.292722e+00 -7.550000e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.050226e-08 -9.992250e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221979e+01 2.078772e+00 -7.300002e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 3.453364e-08 -1.023615e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -1.825128e-08 -1.049725e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.681644e-11 -9.567682e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex 1.222648e+01 -2.178088e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.216567e+01 -2.208704e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.199232e+01 -2.234663e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.173283e+01 -2.252012e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.142670e+01 -2.258110e+01 -7.300004e+00
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -1.147173e+01 -2.258752e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -0.000000e+00 -0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.227195e+01 -2.178774e+01 -7.300004e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.177789e+01 -2.252670e+01 -7.300004e+00
|
||||||
|
vertex -1.221097e+01 -2.209387e+01 -7.300004e+00
|
||||||
|
vertex -1.203748e+01 -2.235336e+01 -7.300004e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.332680e-11 -8.323378e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -5.189548e-09 -8.446005e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex 8.111846e+00 1.647010e+00 -7.300002e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 2.095299e-08 -1.051825e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 3.232708e-11 -1.154344e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -5.516768e+00 2.549339e+01 -7.299999e+00
|
||||||
|
vertex -1.158520e+01 2.549169e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -9.700132e-09 -1.578699e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex 8.111846e+00 1.293843e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 5.769867e-08 -8.630008e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.185306e+01 2.543833e+01 -7.299999e+00
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 9.728713e-08 -6.496578e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.208012e+01 2.528653e+01 -7.299999e+00
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 1.573083e-07 -3.124460e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex -1.223179e+01 2.505939e+01 -7.299999e+00
|
||||||
|
vertex -1.228500e+01 2.479150e+01 -7.299999e+00
|
||||||
|
vertex -5.513295e+00 1.310097e+01 -7.300001e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal -2.594791e-08 -1.154239e-07 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 5.416704e+00 1.310403e+01 -7.300001e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
facet normal 0.000000e+00 -9.739662e-08 1.000000e+00
|
||||||
|
outer loop
|
||||||
|
vertex 1.221323e+01 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 5.413230e+00 2.549836e+01 -7.299999e+00
|
||||||
|
vertex 1.221597e+01 1.570670e+01 -7.300000e+00
|
||||||
|
endloop
|
||||||
|
endfacet
|
||||||
|
endsolid
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta http-equiv="refresh" content="5;url=http://fontsgeek.com/fonts/pigiarniq-italic?ref=readme">
|
||||||
|
<title>Pigiarniq ItalicFontsgeek</title>
|
||||||
|
<style>
|
||||||
|
/* -------------------------------------
|
||||||
|
GLOBAL
|
||||||
|
------------------------------------- */
|
||||||
|
* {
|
||||||
|
margin:0;
|
||||||
|
padding:0;
|
||||||
|
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 100%;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
-webkit-font-smoothing:antialiased;
|
||||||
|
-webkit-text-size-adjust:none;
|
||||||
|
width: 100%!important;
|
||||||
|
height: 100%;
|
||||||
|
background:#DDD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------
|
||||||
|
ELEMENTS
|
||||||
|
------------------------------------- */
|
||||||
|
a {
|
||||||
|
color: #348eda;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary, .btn-secondary {
|
||||||
|
text-decoration:none;
|
||||||
|
color: #FFF;
|
||||||
|
background-color: #348eda;
|
||||||
|
padding:10px 20px;
|
||||||
|
font-weight:bold;
|
||||||
|
margin: 20px 10px 20px 0;
|
||||||
|
text-align:center;
|
||||||
|
cursor:pointer;
|
||||||
|
display: inline-block;
|
||||||
|
border-radius: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary{
|
||||||
|
background: #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.last {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.first{
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------
|
||||||
|
BODY
|
||||||
|
------------------------------------- */
|
||||||
|
table.body-wrap {
|
||||||
|
width: 100%;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.body-wrap .container{
|
||||||
|
border: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------
|
||||||
|
FOOTER
|
||||||
|
------------------------------------- */
|
||||||
|
table.footer-wrap {
|
||||||
|
width: 100%;
|
||||||
|
clear:both!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-wrap .container p {
|
||||||
|
font-size:12px;
|
||||||
|
color:#666;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
table.footer-wrap a{
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------
|
||||||
|
TYPOGRAPHY
|
||||||
|
------------------------------------- */
|
||||||
|
h1,h2,h3{
|
||||||
|
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; line-height: 1.1; margin-bottom:15px; color:#000;
|
||||||
|
margin: 40px 0 10px;
|
||||||
|
line-height: 1.2;
|
||||||
|
font-weight:200;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 36px;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 28px;
|
||||||
|
}
|
||||||
|
h3 {
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p, ul {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size:14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
margin-left:5px;
|
||||||
|
list-style-position: inside;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------
|
||||||
|
RESPONSIVENESS
|
||||||
|
Nuke it from orbit. It's the only way to be sure.
|
||||||
|
------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
|
||||||
|
.container {
|
||||||
|
display:block!important;
|
||||||
|
max-width:600px!important;
|
||||||
|
margin:0 auto!important; /* makes it centered */
|
||||||
|
clear:both!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This should also be a block element, so that it will fill 100% of the .container */
|
||||||
|
.content {
|
||||||
|
padding:20px;
|
||||||
|
max-width:600px;
|
||||||
|
margin:0 auto;
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Let's make sure tables in the content area are 100% wide */
|
||||||
|
.content table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#f6f6f6">
|
||||||
|
|
||||||
|
<!-- body -->
|
||||||
|
<table class="body-wrap">
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td class="container" bgcolor="#FFFFFF">
|
||||||
|
|
||||||
|
<!-- content -->
|
||||||
|
<div class="content">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h1>Pigiarniq Italic</h1>
|
||||||
|
<p>This font was downloaded from <a href="http://fontsgeek.com?ref=readme">fontsgeek.com</a> . You can visit <a href="http://fontsgeek.com?ref=readme">fontsgeek.com</a> for thousands of free fonts.</p>
|
||||||
|
<p><a href="http://fontsgeek.com/fonts/pigiarniq-italic?ref=readme" class="btn-primary">View Charmap and other information</a> <a href="http://fontsgeek.com?ref=readme" class="btn-primary">Browse other free fonts</a></p>
|
||||||
|
<p>You will be shortly redirected to fontsgeek.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!-- /content -->
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<!-- /body -->
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
-------------------------------
|
||||||
|
UBUNTU FONT LICENCE Version 1.0
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
This licence allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely. The fonts, including any derivative works, can be
|
||||||
|
bundled, embedded, and redistributed provided the terms of this licence
|
||||||
|
are met. The fonts and derivatives, however, cannot be released under
|
||||||
|
any other licence. The requirement for fonts to remain under this
|
||||||
|
licence does not require any document created using the fonts or their
|
||||||
|
derivatives to be published under this licence, as long as the primary
|
||||||
|
purpose of the document is not to be a vehicle for the distribution of
|
||||||
|
the fonts.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this licence and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components
|
||||||
|
as received under this licence.
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to
|
||||||
|
a new environment.
|
||||||
|
|
||||||
|
"Copyright Holder(s)" refers to all individuals and companies who have a
|
||||||
|
copyright ownership of the Font Software.
|
||||||
|
|
||||||
|
"Substantially Changed" refers to Modified Versions which can be easily
|
||||||
|
identified as dissimilar to the Font Software by users of the Font
|
||||||
|
Software comparing the Original Version with the Modified Version.
|
||||||
|
|
||||||
|
To "Propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification and with or without charging
|
||||||
|
a redistribution fee), making available to the public, and in some
|
||||||
|
countries other activities as well.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
This licence does not grant any rights under trademark law and all such
|
||||||
|
rights are reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of the Font Software, to propagate the Font Software, subject to
|
||||||
|
the below conditions:
|
||||||
|
|
||||||
|
1) Each copy of the Font Software must contain the above copyright
|
||||||
|
notice and this licence. These can be included either as stand-alone
|
||||||
|
text files, human-readable headers or in the appropriate machine-
|
||||||
|
readable metadata fields within text or binary files as long as those
|
||||||
|
fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
2) The font name complies with the following:
|
||||||
|
(a) The Original Version must retain its name, unmodified.
|
||||||
|
(b) Modified Versions which are Substantially Changed must be renamed to
|
||||||
|
avoid use of the name of the Original Version or similar names entirely.
|
||||||
|
(c) Modified Versions which are not Substantially Changed must be
|
||||||
|
renamed to both (i) retain the name of the Original Version and (ii) add
|
||||||
|
additional naming elements to distinguish the Modified Version from the
|
||||||
|
Original Version. The name of such Modified Versions must be the name of
|
||||||
|
the Original Version, with "derivative X" where X represents the name of
|
||||||
|
the new work, appended to that name.
|
||||||
|
|
||||||
|
3) The name(s) of the Copyright Holder(s) and any contributor to the
|
||||||
|
Font Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except (i) as required by this licence, (ii) to
|
||||||
|
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with
|
||||||
|
their explicit written permission.
|
||||||
|
|
||||||
|
4) The Font Software, modified or unmodified, in part or in whole, must
|
||||||
|
be distributed entirely under this licence, and must not be distributed
|
||||||
|
under any other licence. The requirement for fonts to remain under this
|
||||||
|
licence does not affect any document created using the Font Software,
|
||||||
|
except any version of the Font Software extracted from a document
|
||||||
|
created using the Font Software may only be distributed under this
|
||||||
|
licence.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This licence becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
|
||||||
|
DEALINGS IN THE FONT SOFTWARE.
|
||||||
|
After Width: | Height: | Size: 7.3 MiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,9 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/dns_captive.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
lwip
|
||||||
|
esp_netif
|
||||||
|
)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// File: dns_captive.c
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/http_portal.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
esp_wifi
|
||||||
|
esp_http_server
|
||||||
|
esp_netif
|
||||||
|
storage
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// http_portal.h
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
// Callbacks, die das Portal nach außen benutzt
|
||||||
|
typedef struct {
|
||||||
|
bool (*load_sta_creds)(char **ssid, char **pass); // optional, wenn du es später brauchst
|
||||||
|
void (*save_sta_creds_and_reconnect)(const char *ssid, const char *pass);
|
||||||
|
void (*save_device_info)(
|
||||||
|
const char *devicename,
|
||||||
|
const char *token,
|
||||||
|
const char *bucket,
|
||||||
|
const char *org
|
||||||
|
);
|
||||||
|
} portal_http_callbacks_t;
|
||||||
|
|
||||||
|
// HTTP-Portal starten / stoppen
|
||||||
|
esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
|
||||||
|
EventBits_t bit_gotip,
|
||||||
|
EventBits_t bit_fail,
|
||||||
|
const char* ap_ssid,
|
||||||
|
const portal_http_callbacks_t *cb);
|
||||||
|
|
||||||
|
void portal_http_stop(void);
|
||||||
@@ -14,9 +14,7 @@
|
|||||||
#include "http_portal.h"
|
#include "http_portal.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
|
||||||
// Diese beiden werden vom WiFi-Manager bereitgestellt (in wifi_mgr.c definiert)
|
static portal_http_callbacks_t s_cb;
|
||||||
bool wifi_mgr_load_sta_creds(char **out_ssid, char **out_pass);
|
|
||||||
void wifi_mgr_save_sta_creds_and_reconnect(const char* ssid, const char* pass);
|
|
||||||
|
|
||||||
static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* key) {
|
static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* key) {
|
||||||
size_t len = httpd_req_get_hdr_value_len(req, key);
|
size_t len = httpd_req_get_hdr_value_len(req, key);
|
||||||
@@ -34,9 +32,6 @@ static void __attribute__((unused)) log_one_hdr(httpd_req_t *req, const char* ke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Geräteeigenschaften speichern (in wifi_mgr.c implementieren)
|
|
||||||
void wifi_mgr_save_device_info(const char* devicename, const char* token, const char* bucket, const char* org);
|
|
||||||
|
|
||||||
static const char *TAG = "portal_http";
|
static const char *TAG = "portal_http";
|
||||||
|
|
||||||
static httpd_handle_t s_http = NULL;
|
static httpd_handle_t s_http = NULL;
|
||||||
@@ -460,16 +455,21 @@ static esp_err_t save_post(httpd_req_t *req) {
|
|||||||
log_resp_basic("save_post", "200 OK", "text/html; charset=utf-8", (int)strlen(saved_html));
|
log_resp_basic("save_post", "200 OK", "text/html; charset=utf-8", (int)strlen(saved_html));
|
||||||
httpd_resp_send(req, saved_html, HTTPD_RESP_USE_STRLEN);
|
httpd_resp_send(req, saved_html, HTTPD_RESP_USE_STRLEN);
|
||||||
|
|
||||||
// Geräteeigenschaften speichern
|
// Geräteeigenschaften speichern (über Callback)
|
||||||
wifi_mgr_save_device_info(
|
if (s_cb.save_device_info) {
|
||||||
dev,
|
s_cb.save_device_info(
|
||||||
(token && token[0]) ? token : NULL, // NULL = nicht geändert
|
dev,
|
||||||
(bucket && bucket[0]) ? bucket : NULL,
|
(token && token[0]) ? token : NULL, // NULL = nicht geändert
|
||||||
(org && org[0]) ? org : NULL
|
(bucket && bucket[0]) ? bucket : NULL,
|
||||||
);
|
(org && org[0]) ? org : NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// STA-Creds speichern & reconnect (über Callback)
|
||||||
|
if (s_cb.save_sta_creds_and_reconnect) {
|
||||||
|
s_cb.save_sta_creds_and_reconnect(ssid, pass);
|
||||||
|
}
|
||||||
|
|
||||||
// STA-Creds speichern & reconnect
|
|
||||||
wifi_mgr_save_sta_creds_and_reconnect(ssid, pass);
|
|
||||||
s_force_captive = false; // Captive beenden; OS darf 204 sehen
|
s_force_captive = false; // Captive beenden; OS darf 204 sehen
|
||||||
|
|
||||||
// Cleanup (Erfolgsweg)
|
// Cleanup (Erfolgsweg)
|
||||||
@@ -653,8 +653,12 @@ static httpd_handle_t start_http(void) {
|
|||||||
esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
|
esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
|
||||||
EventBits_t bit_gotip,
|
EventBits_t bit_gotip,
|
||||||
EventBits_t bit_fail,
|
EventBits_t bit_fail,
|
||||||
const char* ap_ssid)
|
const char* ap_ssid,
|
||||||
|
const portal_http_callbacks_t *cb)
|
||||||
{
|
{
|
||||||
|
if (s_http) return ESP_OK;
|
||||||
|
if (!cb) return ESP_ERR_INVALID_ARG;
|
||||||
|
s_cb = *cb;
|
||||||
if (s_http) return ESP_OK;
|
if (s_http) return ESP_OK;
|
||||||
s_wifi_events = wifi_events;
|
s_wifi_events = wifi_events;
|
||||||
s_BIT_GOTIP = bit_gotip;
|
s_BIT_GOTIP = bit_gotip;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/net_influx.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
mdns
|
||||||
|
esp_netif
|
||||||
|
esp_wifi
|
||||||
|
storage
|
||||||
|
esp_http_client
|
||||||
|
sys_status
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// File: include/net_influx.h (oder wo dein Header liegt)
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NET_INFLUX_F_FLOAT,
|
||||||
|
NET_INFLUX_F_INT,
|
||||||
|
NET_INFLUX_F_UINT,
|
||||||
|
NET_INFLUX_F_BOOL,
|
||||||
|
NET_INFLUX_F_STRING,
|
||||||
|
} net_influx_field_type_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* key; // field key
|
||||||
|
net_influx_field_type_t type;
|
||||||
|
int precision; // nur für FLOAT (z.B. 1,3). sonst ignoriert
|
||||||
|
union {
|
||||||
|
double f;
|
||||||
|
int64_t i;
|
||||||
|
uint64_t u;
|
||||||
|
bool b;
|
||||||
|
const char* s;
|
||||||
|
} v;
|
||||||
|
} net_influx_field_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* measurement; // z.B. "air"
|
||||||
|
const char* tags; // z.B. "device=xyz,location=lab" (optional, kann NULL sein)
|
||||||
|
uint64_t ts_ms; // 0 => server time
|
||||||
|
const net_influx_field_t* fields;
|
||||||
|
size_t num_fields;
|
||||||
|
} net_influx_point_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// Task/Queue
|
||||||
|
uint16_t queue_len; // z.B. 16
|
||||||
|
uint32_t task_stack; // z.B. 6144
|
||||||
|
UBaseType_t task_prio; // z.B. 5
|
||||||
|
|
||||||
|
// Init/Retry/Backoff
|
||||||
|
uint32_t init_retry_ms; // z.B. 1000
|
||||||
|
uint32_t backoff_start_ms; // z.B. 2000
|
||||||
|
uint32_t backoff_max_ms; // z.B. 300000
|
||||||
|
uint8_t fails_before_reinit; // z.B. 5
|
||||||
|
|
||||||
|
// Influx init
|
||||||
|
const char* ca_cert_pem_opt; // optional
|
||||||
|
int http_timeout_ms; // z.B. 3000
|
||||||
|
} net_influx_runtime_cfg_t;
|
||||||
|
|
||||||
|
// Bestehende Funktionen bleiben:
|
||||||
|
typedef struct {
|
||||||
|
const char* url_base;
|
||||||
|
const char* org;
|
||||||
|
const char* bucket;
|
||||||
|
const char* token;
|
||||||
|
bool use_tls;
|
||||||
|
const char* ca_cert_pem;
|
||||||
|
int http_timeout_ms;
|
||||||
|
} net_influx_cfg_t;
|
||||||
|
|
||||||
|
esp_err_t net_influx_init(const net_influx_cfg_t* cfg);
|
||||||
|
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms);
|
||||||
|
|
||||||
|
// NEU:
|
||||||
|
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt);
|
||||||
|
void net_influx_stop(void);
|
||||||
|
|
||||||
|
// Asynchron: kopiert point+felder intern und queued sie.
|
||||||
|
// Rückgabe:
|
||||||
|
// - ESP_OK: queued
|
||||||
|
// - ESP_ERR_NO_MEM / ESP_ERR_INVALID_ARG / ESP_FAIL: sonst
|
||||||
|
esp_err_t net_influx_submit_point(const net_influx_point_t* p);
|
||||||
|
|
||||||
|
// Optional (falls du synchron brauchst, bleibt deine alte API nutzbar):
|
||||||
|
esp_err_t net_influx_write_fields(const char* measurement,
|
||||||
|
const char* tags,
|
||||||
|
uint64_t ts_ms,
|
||||||
|
const char* fields_fmt,
|
||||||
|
...);
|
||||||
@@ -0,0 +1,719 @@
|
|||||||
|
// File: src/net_influx.c
|
||||||
|
#include "esp_http_client.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "sys_status.h"
|
||||||
|
#include "storage.h"
|
||||||
|
#include "net_influx.h"
|
||||||
|
|
||||||
|
static const char* TAG = "net_influx";
|
||||||
|
|
||||||
|
/* ---------------- State (mit internen Kopien!) ---------------- */
|
||||||
|
typedef struct {
|
||||||
|
char url_base[128];
|
||||||
|
char org[64];
|
||||||
|
char bucket[64];
|
||||||
|
char token[512]; // lang genug für Influx Token
|
||||||
|
bool use_tls;
|
||||||
|
const char* ca_cert_pem;
|
||||||
|
int http_timeout_ms;
|
||||||
|
} net_influx_state_t;
|
||||||
|
|
||||||
|
static net_influx_state_t s = {0};
|
||||||
|
|
||||||
|
/* ---------------- Worker Runtime State (asynchrones Submit) ---------------- */
|
||||||
|
typedef struct {
|
||||||
|
uint16_t queue_len;
|
||||||
|
uint32_t task_stack;
|
||||||
|
UBaseType_t task_prio;
|
||||||
|
|
||||||
|
uint32_t init_retry_ms;
|
||||||
|
uint32_t backoff_start_ms;
|
||||||
|
uint32_t backoff_max_ms;
|
||||||
|
uint8_t fails_before_reinit;
|
||||||
|
|
||||||
|
const char* ca_cert_pem_opt;
|
||||||
|
int http_timeout_ms;
|
||||||
|
} net_influx_runtime_cfg_i_t;
|
||||||
|
|
||||||
|
static QueueHandle_t s_q = NULL;
|
||||||
|
static TaskHandle_t s_task = NULL;
|
||||||
|
static bool s_run = false;
|
||||||
|
|
||||||
|
static net_influx_runtime_cfg_i_t s_rt = {
|
||||||
|
.queue_len = 16,
|
||||||
|
.task_stack = 6144,
|
||||||
|
.task_prio = 5,
|
||||||
|
.init_retry_ms = 1000,
|
||||||
|
.backoff_start_ms = 2000,
|
||||||
|
.backoff_max_ms = 300000,
|
||||||
|
.fails_before_reinit = 5,
|
||||||
|
.ca_cert_pem_opt = NULL,
|
||||||
|
.http_timeout_ms = 3000,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------------- Utils ---------------- */
|
||||||
|
static void trim_inplace(char* p) {
|
||||||
|
if (!p) return;
|
||||||
|
size_t len = strlen(p);
|
||||||
|
size_t a = 0, b = len;
|
||||||
|
while (a < b && (isspace((unsigned char)p[a]) || p[a] == '\"')) a++;
|
||||||
|
while (b > a && (isspace((unsigned char)p[b-1]) || p[b-1] == '\"' || p[b-1] == '/')) b--;
|
||||||
|
if (a || b != len) {
|
||||||
|
memmove(p, p + a, b - a);
|
||||||
|
p[b - a] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void safe_copy(char* dst, size_t dst_sz, const char* src) {
|
||||||
|
if (!dst || dst_sz == 0) return;
|
||||||
|
if (!src) { dst[0] = 0; return; }
|
||||||
|
strncpy(dst, src, dst_sz - 1);
|
||||||
|
dst[dst_sz - 1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool tls; // http=false, https=true
|
||||||
|
char host[64];
|
||||||
|
int port; // -1 = nicht angegeben
|
||||||
|
} base_parts_t;
|
||||||
|
|
||||||
|
// erwartet: "http://host:port" oder "host:port" oder "host"
|
||||||
|
static bool parse_base_url(const char* in, base_parts_t* out) {
|
||||||
|
if (!in || !*in || !out) return false;
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
safe_copy(buf, sizeof(buf), in);
|
||||||
|
trim_inplace(buf);
|
||||||
|
|
||||||
|
const char* p = buf;
|
||||||
|
out->tls = false;
|
||||||
|
out->port = -1;
|
||||||
|
memset(out->host, 0, sizeof(out->host));
|
||||||
|
|
||||||
|
if (strncasecmp(p, "http://", 7) == 0) { p += 7; out->tls = false; }
|
||||||
|
else if (strncasecmp(p, "https://", 8) == 0) { p += 8; out->tls = true; }
|
||||||
|
|
||||||
|
const char* colon = strchr(p, ':');
|
||||||
|
if (colon) {
|
||||||
|
size_t host_len = (size_t)(colon - p);
|
||||||
|
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
|
||||||
|
memcpy(out->host, p, host_len);
|
||||||
|
out->host[host_len] = 0;
|
||||||
|
|
||||||
|
const char* port_str = colon + 1;
|
||||||
|
if (!*port_str) return false;
|
||||||
|
int port = 0;
|
||||||
|
while (*port_str && isdigit((unsigned char)*port_str)) {
|
||||||
|
port = port * 10 + (*port_str - '0');
|
||||||
|
port_str++;
|
||||||
|
}
|
||||||
|
if (*port_str != 0) return false; // kein weiterer Kram erlaubt
|
||||||
|
out->port = port;
|
||||||
|
} else {
|
||||||
|
size_t host_len = strlen(p);
|
||||||
|
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
|
||||||
|
memcpy(out->host, p, host_len);
|
||||||
|
out->host[host_len] = 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mask_token(const char* token, char* out, size_t out_len) {
|
||||||
|
if (!token || !out || out_len < 8) return;
|
||||||
|
size_t n = strlen(token);
|
||||||
|
if (n <= 8) {
|
||||||
|
snprintf(out, out_len, "****");
|
||||||
|
} else {
|
||||||
|
size_t keep = 4;
|
||||||
|
snprintf(out, out_len, "%.*s****%.*s",
|
||||||
|
(int)keep, token,
|
||||||
|
(int)keep, token + n - keep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char* dup0(const char* str) {
|
||||||
|
if (!str) return NULL;
|
||||||
|
size_t n = strlen(str) + 1;
|
||||||
|
char* p = (char*)malloc(n);
|
||||||
|
if (!p) return NULL;
|
||||||
|
memcpy(p, str, n);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Minimal escaping für measurement/key: spaces/commas */
|
||||||
|
static size_t esc_copy(char* dst, size_t cap, const char* src, bool escape_equals) {
|
||||||
|
size_t pos = 0;
|
||||||
|
if (!dst || cap == 0) return 0;
|
||||||
|
dst[0] = 0;
|
||||||
|
if (!src) return 0;
|
||||||
|
|
||||||
|
for (const char* p = src; *p; ++p) {
|
||||||
|
char c = *p;
|
||||||
|
bool esc = (c == ' ' || c == ',' || (escape_equals && c == '='));
|
||||||
|
if (esc) {
|
||||||
|
if (pos + 2 >= cap) break;
|
||||||
|
dst[pos++] = '\\';
|
||||||
|
dst[pos++] = c;
|
||||||
|
} else {
|
||||||
|
if (pos + 1 >= cap) break;
|
||||||
|
dst[pos++] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dst[(pos < cap) ? pos : (cap - 1)] = 0;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- HTTP Event Handler (IDF-kompatibel) ---------------- */
|
||||||
|
static esp_err_t http_evt(esp_http_client_event_t* evt) {
|
||||||
|
switch (evt->event_id) {
|
||||||
|
case HTTP_EVENT_ERROR: ESP_LOGE(TAG, "HTTP_EVENT_ERROR"); break;
|
||||||
|
case HTTP_EVENT_ON_CONNECTED: ESP_LOGI(TAG, "HTTP_EVENT_ON_CONNECTED"); break;
|
||||||
|
case HTTP_EVENT_HEADER_SENT: ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT"); break;
|
||||||
|
case HTTP_EVENT_ON_HEADER:
|
||||||
|
ESP_LOGD(TAG, "HDR: %s: %s",
|
||||||
|
evt->header_key ? evt->header_key : "(null)",
|
||||||
|
evt->header_value ? evt->header_value : "(null)");
|
||||||
|
break;
|
||||||
|
case HTTP_EVENT_ON_DATA: ESP_LOGV(TAG, "DATA chunk len=%d", evt->data_len); break;
|
||||||
|
case HTTP_EVENT_ON_FINISH: ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH"); break;
|
||||||
|
case HTTP_EVENT_DISCONNECTED: ESP_LOGW(TAG, "HTTP_EVENT_DISCONNECTED"); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Internal: HTTP send "line protocol" ---------------- */
|
||||||
|
static esp_err_t net_influx_write_line(const char* line) {
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
if (!line || !*line) {
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (s.url_base[0] == 0 || s.org[0] == 0 || s.bucket[0] == 0 || s.token[0] == 0) {
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base parse → host/port/tls
|
||||||
|
base_parts_t bp;
|
||||||
|
if (!parse_base_url(s.url_base, &bp)) {
|
||||||
|
ESP_LOGE(TAG, "Base-URL ungueltig: \"%s\"", s.url_base);
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (s.use_tls) bp.tls = true;
|
||||||
|
int port = (bp.port > 0) ? bp.port : (bp.tls ? 443 : 8086);
|
||||||
|
|
||||||
|
// Pfad
|
||||||
|
char path[192];
|
||||||
|
snprintf(path, sizeof(path), "/api/v2/write?org=%s&bucket=%s&precision=ms", s.org, s.bucket);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "HTTP cfg: host=%s, port=%d, path=%s, tls=%d", bp.host, port, path, (int)bp.tls);
|
||||||
|
ESP_LOGD(TAG, "Line: %s", line);
|
||||||
|
|
||||||
|
esp_http_client_config_t cfg = {
|
||||||
|
.host = bp.host,
|
||||||
|
.port = port,
|
||||||
|
.path = path,
|
||||||
|
.timeout_ms = s.http_timeout_ms,
|
||||||
|
.cert_pem = bp.tls ? s.ca_cert_pem : NULL,
|
||||||
|
.method = HTTP_METHOD_POST,
|
||||||
|
.event_handler = http_evt,
|
||||||
|
.transport_type = bp.tls ? HTTP_TRANSPORT_OVER_SSL : HTTP_TRANSPORT_OVER_TCP,
|
||||||
|
.disable_auto_redirect = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_http_client_handle_t h = esp_http_client_init(&cfg);
|
||||||
|
if (!h) {
|
||||||
|
ESP_LOGE(TAG, "http_client_init: no mem");
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Header
|
||||||
|
size_t auth_len = strlen(s.token) + 7; // "Token " + '\0'
|
||||||
|
char* auth = (char*)malloc(auth_len);
|
||||||
|
if (!auth) {
|
||||||
|
ESP_LOGE(TAG, "malloc auth header: no mem");
|
||||||
|
esp_http_client_cleanup(h);
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
snprintf(auth, auth_len, "Token %s", s.token);
|
||||||
|
esp_http_client_set_header(h, "Authorization", auth);
|
||||||
|
free(auth);
|
||||||
|
|
||||||
|
esp_http_client_set_header(h, "Content-Type", "text/plain; charset=utf-8");
|
||||||
|
|
||||||
|
esp_err_t err = esp_http_client_set_post_field(h, line, (int)strlen(line));
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "set_post_field: %s", esp_err_to_name(err));
|
||||||
|
esp_http_client_cleanup(h);
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = esp_http_client_perform(h);
|
||||||
|
|
||||||
|
int status = -1;
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
status = esp_http_client_get_status_code(h);
|
||||||
|
int64_t cl = esp_http_client_get_content_length(h);
|
||||||
|
ESP_LOGI(TAG, "HTTP status=%d, content_length=%lld", status, (long long)cl);
|
||||||
|
|
||||||
|
if (status != 204) {
|
||||||
|
char resp[256] = {0};
|
||||||
|
int n = esp_http_client_read_response(h, resp, sizeof(resp)-1);
|
||||||
|
if (n > 0) ESP_LOGW(TAG, "Resp(%d): %.*s", status, n, resp);
|
||||||
|
else ESP_LOGW(TAG, "Resp(%d): <kein Body>", status);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "perform: %s", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_http_client_cleanup(h);
|
||||||
|
|
||||||
|
ok = (err == ESP_OK && status == 204);
|
||||||
|
sys_status_set_influx_ok(ok);
|
||||||
|
return ok ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Generic Point/Fields → Line Protocol ---------------- */
|
||||||
|
static bool field_is_valid(const net_influx_field_t* f) {
|
||||||
|
if (!f || !f->key || !*f->key) return false;
|
||||||
|
if (f->type == NET_INFLUX_F_FLOAT) return isfinite(f->v.f);
|
||||||
|
if (f->type == NET_INFLUX_F_STRING) return (f->v.s != NULL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t build_line_protocol(const net_influx_point_t* p, char* out, size_t out_cap) {
|
||||||
|
if (!p || !p->measurement || !p->fields || p->num_fields == 0 || !out || out_cap < 64) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t off = 0;
|
||||||
|
|
||||||
|
// measurement escaped (space/comma)
|
||||||
|
char meas[96];
|
||||||
|
esc_copy(meas, sizeof(meas), p->measurement, false);
|
||||||
|
off += snprintf(out + off, out_cap - off, "%s", meas);
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
|
||||||
|
// tags: passthrough (caller liefert "k=v,k2=v2")
|
||||||
|
if (p->tags && *p->tags) {
|
||||||
|
off += snprintf(out + off, out_cap - off, ",%s", p->tags);
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
off += snprintf(out + off, out_cap - off, " ");
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < p->num_fields; ++i) {
|
||||||
|
const net_influx_field_t* f = &p->fields[i];
|
||||||
|
if (!field_is_valid(f)) continue;
|
||||||
|
|
||||||
|
char key[64];
|
||||||
|
esc_copy(key, sizeof(key), f->key, false);
|
||||||
|
|
||||||
|
if (!first) {
|
||||||
|
off += snprintf(out + off, out_cap - off, ",");
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
switch (f->type) {
|
||||||
|
case NET_INFLUX_F_FLOAT: {
|
||||||
|
int prec = (f->precision >= 0 && f->precision <= 9) ? f->precision : 3;
|
||||||
|
char fmt[24];
|
||||||
|
snprintf(fmt, sizeof(fmt), "%%s=%%.%df", prec);
|
||||||
|
off += snprintf(out + off, out_cap - off, fmt, key, f->v.f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NET_INFLUX_F_INT:
|
||||||
|
off += snprintf(out + off, out_cap - off, "%s=%lldi", key, (long long)f->v.i);
|
||||||
|
break;
|
||||||
|
case NET_INFLUX_F_UINT:
|
||||||
|
off += snprintf(out + off, out_cap - off, "%s=%llui", key, (unsigned long long)f->v.u);
|
||||||
|
break;
|
||||||
|
case NET_INFLUX_F_BOOL:
|
||||||
|
off += snprintf(out + off, out_cap - off, "%s=%s", key, f->v.b ? "true" : "false");
|
||||||
|
break;
|
||||||
|
case NET_INFLUX_F_STRING: {
|
||||||
|
off += snprintf(out + off, out_cap - off, "%s=\"", key);
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
|
||||||
|
const char* s0 = f->v.s ? f->v.s : "";
|
||||||
|
for (const char* sp = s0; *sp; ++sp) {
|
||||||
|
if (off + 2 >= out_cap) return ESP_FAIL;
|
||||||
|
if (*sp == '\"' || *sp == '\\') out[off++] = '\\';
|
||||||
|
out[off++] = *sp;
|
||||||
|
}
|
||||||
|
if (off + 2 >= out_cap) return ESP_FAIL;
|
||||||
|
out[off++] = '\"';
|
||||||
|
out[off] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first) return ESP_ERR_INVALID_STATE; // keine validen Felder
|
||||||
|
|
||||||
|
if (p->ts_ms != 0) {
|
||||||
|
off += snprintf(out + off, out_cap - off, " %llu", (unsigned long long)p->ts_ms);
|
||||||
|
if (off >= out_cap) return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Async Queue Message (deep copy) ---------------- */
|
||||||
|
typedef struct {
|
||||||
|
char* measurement;
|
||||||
|
char* tags; // optional
|
||||||
|
uint64_t ts_ms;
|
||||||
|
|
||||||
|
size_t num_fields;
|
||||||
|
net_influx_field_t* fields; // deep-copied array; keys and string-values are duplicated
|
||||||
|
} influx_msg_t;
|
||||||
|
|
||||||
|
static void free_msg(influx_msg_t* m) {
|
||||||
|
if (!m) return;
|
||||||
|
if (m->measurement) free(m->measurement);
|
||||||
|
if (m->tags) free(m->tags);
|
||||||
|
if (m->fields) {
|
||||||
|
for (size_t i = 0; i < m->num_fields; ++i) {
|
||||||
|
if (m->fields[i].type == NET_INFLUX_F_STRING && m->fields[i].v.s) {
|
||||||
|
free((void*)m->fields[i].v.s);
|
||||||
|
}
|
||||||
|
if (m->fields[i].key) free((void*)m->fields[i].key);
|
||||||
|
}
|
||||||
|
free(m->fields);
|
||||||
|
}
|
||||||
|
memset(m, 0, sizeof(*m));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Init/Backoff (im Worker) ---------------- */
|
||||||
|
static bool influx_init_blocking(void) {
|
||||||
|
while (s_run) {
|
||||||
|
if (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "Influx ready (from NVS).");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ESP_LOGW(TAG, "Influx nicht bereit – retry in %u ms", (unsigned)s_rt.init_retry_ms);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(s_rt.init_retry_ms));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool influx_reinit_with_backoff(uint32_t* backoff_ms) {
|
||||||
|
if (!backoff_ms) return false;
|
||||||
|
|
||||||
|
uint32_t wait_ms = (*backoff_ms == 0) ? s_rt.backoff_start_ms : *backoff_ms;
|
||||||
|
ESP_LOGW(TAG, "Re-Init Influx in %u ms", (unsigned)wait_ms);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(wait_ms));
|
||||||
|
|
||||||
|
bool ok = (net_influx_init_from_nvs(s_rt.ca_cert_pem_opt, s_rt.http_timeout_ms) == ESP_OK);
|
||||||
|
if (ok) {
|
||||||
|
ESP_LOGI(TAG, "Influx Re-Init OK");
|
||||||
|
*backoff_ms = s_rt.backoff_start_ms;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wait_ms < s_rt.backoff_max_ms) {
|
||||||
|
uint32_t next = wait_ms * 2;
|
||||||
|
*backoff_ms = (next > s_rt.backoff_max_ms) ? s_rt.backoff_max_ms : next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Worker Task ---------------- */
|
||||||
|
static void net_influx_worker(void* arg) {
|
||||||
|
(void)arg;
|
||||||
|
ESP_LOGI(TAG, "Influx worker started.");
|
||||||
|
|
||||||
|
if (!influx_init_blocking()) {
|
||||||
|
ESP_LOGE(TAG, "Worker beendet (Influx init fatal).");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fail_count = 0;
|
||||||
|
uint32_t backoff_ms = s_rt.backoff_start_ms;
|
||||||
|
|
||||||
|
while (s_run) {
|
||||||
|
influx_msg_t msg = {0};
|
||||||
|
if (xQueueReceive(s_q, &msg, portMAX_DELAY) != pdTRUE) continue;
|
||||||
|
|
||||||
|
net_influx_point_t p = {
|
||||||
|
.measurement = msg.measurement,
|
||||||
|
.tags = msg.tags,
|
||||||
|
.ts_ms = msg.ts_ms,
|
||||||
|
.fields = msg.fields,
|
||||||
|
.num_fields = msg.num_fields,
|
||||||
|
};
|
||||||
|
|
||||||
|
char line[512];
|
||||||
|
esp_err_t b = build_line_protocol(&p, line, sizeof(line));
|
||||||
|
|
||||||
|
if (b == ESP_ERR_INVALID_STATE) {
|
||||||
|
ESP_LOGW(TAG, "Skipping write: no valid fields.");
|
||||||
|
free_msg(&msg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (b != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "Line build failed: %s", esp_err_to_name(b));
|
||||||
|
free_msg(&msg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t e = net_influx_write_line(line);
|
||||||
|
|
||||||
|
if (e == ESP_OK) {
|
||||||
|
if (fail_count) ESP_LOGI(TAG, "Influx write recovered.");
|
||||||
|
fail_count = 0;
|
||||||
|
backoff_ms = s_rt.backoff_start_ms;
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Influx write failed: %s", esp_err_to_name(e));
|
||||||
|
if (++fail_count >= (int)s_rt.fails_before_reinit) {
|
||||||
|
(void)influx_reinit_with_backoff(&backoff_ms);
|
||||||
|
fail_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_msg(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Influx worker stopping.");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- Public API ---------------- */
|
||||||
|
esp_err_t net_influx_init(const net_influx_cfg_t* cfg) {
|
||||||
|
if (!cfg || !cfg->url_base || !cfg->org || !cfg->bucket || !cfg->token) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
safe_copy(s.url_base, sizeof(s.url_base), cfg->url_base);
|
||||||
|
safe_copy(s.org, sizeof(s.org), cfg->org);
|
||||||
|
safe_copy(s.bucket, sizeof(s.bucket), cfg->bucket);
|
||||||
|
safe_copy(s.token, sizeof(s.token), cfg->token);
|
||||||
|
trim_inplace(s.url_base);
|
||||||
|
|
||||||
|
s.use_tls = cfg->use_tls;
|
||||||
|
s.ca_cert_pem = cfg->ca_cert_pem;
|
||||||
|
s.http_timeout_ms = (cfg->http_timeout_ms > 0) ? cfg->http_timeout_ms : 3000;
|
||||||
|
|
||||||
|
char tok[32] = {0};
|
||||||
|
mask_token(s.token, tok, sizeof(tok));
|
||||||
|
ESP_LOGI(TAG, "init: base=\"%s\", org=\"%s\", bucket=\"%s\", tls=%d, timeout=%dms, token=%s",
|
||||||
|
s.url_base, s.org, s.bucket, (int)s.use_tls, s.http_timeout_ms, tok);
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t net_influx_write_fields(const char* measurement,
|
||||||
|
const char* tags,
|
||||||
|
uint64_t ts_ms,
|
||||||
|
const char* fields_fmt,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
// --- pessimistisch starten ---
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
if (!measurement || !fields_fmt) {
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (s.url_base[0] == 0 || s.org[0] == 0 || s.bucket[0] == 0 || s.token[0] == 0) {
|
||||||
|
sys_status_set_influx_ok(false);
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1) Fields formatieren
|
||||||
|
char fields[256];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fields_fmt);
|
||||||
|
vsnprintf(fields, sizeof(fields), fields_fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
// 2) Line Protocol
|
||||||
|
char line[512];
|
||||||
|
int off = 0;
|
||||||
|
|
||||||
|
// measurement escaping (space/comma)
|
||||||
|
char meas[96];
|
||||||
|
esc_copy(meas, sizeof(meas), measurement, false);
|
||||||
|
|
||||||
|
off += snprintf(line + off, sizeof(line) - off, "%s", meas);
|
||||||
|
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
||||||
|
if (tags && *tags) {
|
||||||
|
off += snprintf(line + off, sizeof(line) - off, ",%s", tags);
|
||||||
|
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
||||||
|
}
|
||||||
|
off += snprintf(line + off, sizeof(line) - off, " %s", fields);
|
||||||
|
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
||||||
|
if (ts_ms != 0) {
|
||||||
|
off += snprintf(line + off, sizeof(line) - off, " %llu", (unsigned long long)ts_ms);
|
||||||
|
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; }
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = net_influx_write_line(line);
|
||||||
|
|
||||||
|
ok = (err == ESP_OK);
|
||||||
|
sys_status_set_influx_ok(ok);
|
||||||
|
return ok ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aus NVS: URL (service_url), org/bucket/token → net_influx_init()
|
||||||
|
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms)
|
||||||
|
{
|
||||||
|
char *url = NULL, *org = NULL, *bucket = NULL, *token = NULL;
|
||||||
|
|
||||||
|
if (!storage_load_service_url(&url)) {
|
||||||
|
ESP_LOGW(TAG, "keine Service-URL in NVS gefunden (mDNS noch nicht fertig?)");
|
||||||
|
return ESP_ERR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (!storage_get_effective_influx(&org, &bucket, &token)) {
|
||||||
|
ESP_LOGE(TAG, "Influx-Konfiguration aus NVS nicht lesbar");
|
||||||
|
free(url);
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
net_influx_cfg_t cfg = {
|
||||||
|
.url_base = url, // z.B. "http://192.168.1.10:8086"
|
||||||
|
.org = org,
|
||||||
|
.bucket = bucket,
|
||||||
|
.token = token,
|
||||||
|
.use_tls = false, // URL-Parser erkennt https automatisch; true erzwingt TLS
|
||||||
|
.ca_cert_pem = ca_cert_pem_opt,
|
||||||
|
.http_timeout_ms = (timeout_ms > 0) ? timeout_ms : 3000
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_err_t err = net_influx_init(&cfg);
|
||||||
|
|
||||||
|
free(url);
|
||||||
|
free(org);
|
||||||
|
free(bucket);
|
||||||
|
free(token);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- NEW: Start/Stop/Submit (generic, multi-sensor) ---------------- */
|
||||||
|
esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt) {
|
||||||
|
if (s_task) return ESP_OK;
|
||||||
|
|
||||||
|
// runtime cfg übernehmen (mit Defaults)
|
||||||
|
if (rt) {
|
||||||
|
s_rt.queue_len = rt->queue_len ? rt->queue_len : s_rt.queue_len;
|
||||||
|
s_rt.task_stack = rt->task_stack ? rt->task_stack : s_rt.task_stack;
|
||||||
|
s_rt.task_prio = rt->task_prio ? rt->task_prio : s_rt.task_prio;
|
||||||
|
|
||||||
|
s_rt.init_retry_ms = rt->init_retry_ms ? rt->init_retry_ms : s_rt.init_retry_ms;
|
||||||
|
s_rt.backoff_start_ms = rt->backoff_start_ms ? rt->backoff_start_ms : s_rt.backoff_start_ms;
|
||||||
|
s_rt.backoff_max_ms = rt->backoff_max_ms ? rt->backoff_max_ms : s_rt.backoff_max_ms;
|
||||||
|
s_rt.fails_before_reinit = rt->fails_before_reinit ? rt->fails_before_reinit : s_rt.fails_before_reinit;
|
||||||
|
|
||||||
|
s_rt.ca_cert_pem_opt = rt->ca_cert_pem_opt;
|
||||||
|
s_rt.http_timeout_ms = (rt->http_timeout_ms > 0) ? rt->http_timeout_ms : s_rt.http_timeout_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_q = xQueueCreate(s_rt.queue_len, sizeof(influx_msg_t));
|
||||||
|
if (!s_q) return ESP_ERR_NO_MEM;
|
||||||
|
|
||||||
|
s_run = true;
|
||||||
|
if (xTaskCreate(net_influx_worker, "influx_worker", s_rt.task_stack, NULL, s_rt.task_prio, &s_task) != pdPASS) {
|
||||||
|
vQueueDelete(s_q);
|
||||||
|
s_q = NULL;
|
||||||
|
s_run = false;
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_influx_stop(void) {
|
||||||
|
s_run = false;
|
||||||
|
|
||||||
|
if (s_task) {
|
||||||
|
vTaskDelete(s_task);
|
||||||
|
s_task = NULL;
|
||||||
|
}
|
||||||
|
if (s_q) {
|
||||||
|
influx_msg_t msg;
|
||||||
|
while (xQueueReceive(s_q, &msg, 0) == pdTRUE) {
|
||||||
|
free_msg(&msg);
|
||||||
|
}
|
||||||
|
vQueueDelete(s_q);
|
||||||
|
s_q = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t net_influx_submit_point(const net_influx_point_t* p) {
|
||||||
|
if (!p || !p->measurement || !*p->measurement || !p->fields || p->num_fields == 0) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (!s_q) return ESP_ERR_INVALID_STATE;
|
||||||
|
|
||||||
|
influx_msg_t msg = {0};
|
||||||
|
msg.measurement = dup0(p->measurement);
|
||||||
|
msg.tags = (p->tags && *p->tags) ? dup0(p->tags) : NULL;
|
||||||
|
msg.ts_ms = p->ts_ms;
|
||||||
|
msg.num_fields = p->num_fields;
|
||||||
|
|
||||||
|
msg.fields = (net_influx_field_t*)calloc(p->num_fields, sizeof(net_influx_field_t));
|
||||||
|
if (!msg.measurement || !msg.fields) {
|
||||||
|
free_msg(&msg);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < p->num_fields; ++i) {
|
||||||
|
msg.fields[i] = p->fields[i];
|
||||||
|
|
||||||
|
// deep copy key
|
||||||
|
msg.fields[i].key = dup0(p->fields[i].key);
|
||||||
|
if (!msg.fields[i].key) {
|
||||||
|
free_msg(&msg);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// deep copy string value if needed
|
||||||
|
if (p->fields[i].type == NET_INFLUX_F_STRING && p->fields[i].v.s) {
|
||||||
|
msg.fields[i].v.s = dup0(p->fields[i].v.s);
|
||||||
|
if (!msg.fields[i].v.s) {
|
||||||
|
free_msg(&msg);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-blocking enqueue; wenn voll: drop oldest
|
||||||
|
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
|
||||||
|
influx_msg_t dump;
|
||||||
|
if (xQueueReceive(s_q, &dump, 0) == pdTRUE) free_msg(&dump);
|
||||||
|
|
||||||
|
if (xQueueSend(s_q, &msg, 0) != pdPASS) {
|
||||||
|
free_msg(&msg);
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/net_mdns.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
mdns
|
||||||
|
esp_netif
|
||||||
|
esp_wifi
|
||||||
|
storage
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// net_mdns.h (Ergänzungen)
|
||||||
|
#pragma once
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "mdns.h"
|
||||||
|
|
||||||
|
// bestehende APIs bleiben...
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *service; // z.B. "_myapp"
|
||||||
|
const char *proto; // z.B. "_tcp"
|
||||||
|
int enforce_port; // -1 oder 0 = egal
|
||||||
|
|
||||||
|
const char *fallback_service; // z.B. "_http"
|
||||||
|
const char *fallback_proto; // z.B. "_tcp"
|
||||||
|
int fallback_port; // z.B. 8086
|
||||||
|
|
||||||
|
const char *txt_key; // optional
|
||||||
|
const char *txt_value; // optional
|
||||||
|
|
||||||
|
uint32_t query_timeout_ms; // z.B. 2000
|
||||||
|
uint32_t retry_interval_ms; // z.B. 60000
|
||||||
|
int max_results; // z.B. 5
|
||||||
|
|
||||||
|
const char *instance_prefix; // z.B. "myapp-"
|
||||||
|
bool require_instance_prefix; // true/false
|
||||||
|
} net_mdns_discover_cfg_t;
|
||||||
|
|
||||||
|
esp_err_t net_mdns_autodiscover_start(const net_mdns_discover_cfg_t *cfg);
|
||||||
|
void net_mdns_autodiscover_stop(void);
|
||||||
|
esp_err_t net_mdns_autostart_init(const char* hostname, const char* instance_name);
|
||||||
@@ -0,0 +1,477 @@
|
|||||||
|
// File: firmware/components/net_mdns/src/net_mdns.c
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
#include "mdns.h"
|
||||||
|
#include "net_mdns.h"
|
||||||
|
#include "storage.h"
|
||||||
|
|
||||||
|
static const char *TAG = "net_mdns";
|
||||||
|
|
||||||
|
// -------------------- Global State --------------------
|
||||||
|
static char g_hostname[33] = {0};
|
||||||
|
static char g_instance[33] = {0};
|
||||||
|
|
||||||
|
static volatile bool g_mdns_running = false;
|
||||||
|
static volatile bool g_autostart_inited = false;
|
||||||
|
|
||||||
|
// Event handler instance handles (damit nicht mehrfach registriert wird)
|
||||||
|
static esp_event_handler_instance_t g_ip_handler = NULL;
|
||||||
|
static esp_event_handler_instance_t g_wifi_handler = NULL;
|
||||||
|
|
||||||
|
// Discovery task state
|
||||||
|
static TaskHandle_t g_discover_task = NULL;
|
||||||
|
|
||||||
|
// Konfiguration für Discovery-Retry (interne Kopie)
|
||||||
|
typedef struct {
|
||||||
|
char service[32];
|
||||||
|
char proto[8];
|
||||||
|
int enforce_port;
|
||||||
|
|
||||||
|
char fallback_service[32];
|
||||||
|
char fallback_proto[8];
|
||||||
|
int fallback_port;
|
||||||
|
|
||||||
|
// optional TXT filter (können leer sein)
|
||||||
|
char txt_key[32];
|
||||||
|
char txt_value[64];
|
||||||
|
|
||||||
|
uint32_t query_timeout_ms;
|
||||||
|
uint32_t retry_interval_ms;
|
||||||
|
int max_results;
|
||||||
|
|
||||||
|
// optional: Instanzpräfix-Filter
|
||||||
|
char instance_prefix[16]; // z.B. "myapp-"; leer = kein Filter
|
||||||
|
bool require_instance_prefix;
|
||||||
|
} discover_cfg_t;
|
||||||
|
|
||||||
|
static discover_cfg_t g_discover_cfg = {0};
|
||||||
|
static volatile bool g_discover_enabled = false;
|
||||||
|
|
||||||
|
// -------------------- Forward Declarations (C needs this) --------------------
|
||||||
|
static void mdns_start_if_needed(void);
|
||||||
|
static void mdns_stop_if_running(void);
|
||||||
|
static bool have_sta_ip(void);
|
||||||
|
static void mdns_discover_task(void *arg);
|
||||||
|
static void on_ip_event(void *arg, esp_event_base_t base, int32_t id, void *data);
|
||||||
|
static void on_wifi_event(void *arg, esp_event_base_t base, int32_t id, void *data);
|
||||||
|
|
||||||
|
// These are public (declared in net_mdns.h), but used before their definition in this .c
|
||||||
|
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
|
||||||
|
int enforce_port,
|
||||||
|
const char *txt_key, const char *txt_value,
|
||||||
|
uint32_t timeout_ms);
|
||||||
|
|
||||||
|
bool net_mdns_find_service_url(const char *service, const char *proto,
|
||||||
|
int enforce_port, const char *txt_key, const char *txt_value,
|
||||||
|
uint32_t timeout_ms, int max_results,
|
||||||
|
char *url_out, size_t url_out_size);
|
||||||
|
|
||||||
|
// -------------------- Internal Helpers --------------------
|
||||||
|
static void mdns_start_if_needed(void)
|
||||||
|
{
|
||||||
|
if (g_mdns_running) return;
|
||||||
|
|
||||||
|
esp_err_t err = mdns_init();
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "mdns_init failed: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_hostname[0]) mdns_hostname_set(g_hostname);
|
||||||
|
if (g_instance[0]) mdns_instance_name_set(g_instance);
|
||||||
|
|
||||||
|
g_mdns_running = true;
|
||||||
|
ESP_LOGI(TAG, "mDNS started (host=%s, inst=%s)", g_hostname, g_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mdns_stop_if_running(void)
|
||||||
|
{
|
||||||
|
if (!g_mdns_running) return;
|
||||||
|
|
||||||
|
mdns_free();
|
||||||
|
g_mdns_running = false;
|
||||||
|
ESP_LOGI(TAG, "mDNS stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool have_sta_ip(void)
|
||||||
|
{
|
||||||
|
esp_netif_t *sta = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
||||||
|
if (!sta) return false;
|
||||||
|
|
||||||
|
esp_netif_ip_info_t ip;
|
||||||
|
if (esp_netif_get_ip_info(sta, &ip) != ESP_OK) return false;
|
||||||
|
|
||||||
|
return (ip.ip.addr != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platzhalter: sys_status wird bewusst NICHT in diesem Component gesetzt.
|
||||||
|
static void set_mdns_ok(bool ok)
|
||||||
|
{
|
||||||
|
(void)ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- Discovery Task --------------------
|
||||||
|
static void mdns_discover_task(void *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
|
||||||
|
const uint32_t retry_ms = g_discover_cfg.retry_interval_ms ? g_discover_cfg.retry_interval_ms : 60000;
|
||||||
|
const TickType_t retry_delay = pdMS_TO_TICKS(retry_ms);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG,
|
||||||
|
"mDNS discover task started: primary=%s.%s port=%d fallback=%s.%s port=%d retry=%u ms",
|
||||||
|
g_discover_cfg.service, g_discover_cfg.proto, g_discover_cfg.enforce_port,
|
||||||
|
g_discover_cfg.fallback_service, g_discover_cfg.fallback_proto, g_discover_cfg.fallback_port,
|
||||||
|
(unsigned)retry_ms);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
// Wenn Discovery deaktiviert wurde → sauber beenden
|
||||||
|
if (!g_discover_enabled) {
|
||||||
|
ESP_LOGI(TAG, "mDNS discover disabled; exiting task.");
|
||||||
|
g_discover_task = NULL;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wenn STA nicht online ist → warten
|
||||||
|
if (!have_sta_ip()) {
|
||||||
|
set_mdns_ok(false);
|
||||||
|
vTaskDelay(retry_delay);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mDNS sicherstellen
|
||||||
|
mdns_start_if_needed();
|
||||||
|
if (!g_mdns_running) {
|
||||||
|
set_mdns_ok(false);
|
||||||
|
vTaskDelay(retry_delay);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1) Primary service
|
||||||
|
esp_err_t err = net_mdns_autodiscover_and_store(
|
||||||
|
g_discover_cfg.service,
|
||||||
|
g_discover_cfg.proto,
|
||||||
|
g_discover_cfg.enforce_port,
|
||||||
|
(g_discover_cfg.txt_key[0] ? g_discover_cfg.txt_key : NULL),
|
||||||
|
(g_discover_cfg.txt_value[0] ? g_discover_cfg.txt_value : NULL),
|
||||||
|
g_discover_cfg.query_timeout_ms ? g_discover_cfg.query_timeout_ms : 2000
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2) Fallback service (wenn primary nicht gefunden)
|
||||||
|
if (err != ESP_OK && g_discover_cfg.fallback_service[0] && g_discover_cfg.fallback_proto[0]) {
|
||||||
|
err = net_mdns_autodiscover_and_store(
|
||||||
|
g_discover_cfg.fallback_service,
|
||||||
|
g_discover_cfg.fallback_proto,
|
||||||
|
g_discover_cfg.fallback_port,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
g_discover_cfg.query_timeout_ms ? g_discover_cfg.query_timeout_ms : 2000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
set_mdns_ok(true);
|
||||||
|
ESP_LOGI(TAG, "mDNS: service found & stored; stopping discover task.");
|
||||||
|
g_discover_enabled = false; // Einmal finden reicht (wie zuvor in wifi_mgr)
|
||||||
|
g_discover_task = NULL;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
set_mdns_ok(false);
|
||||||
|
ESP_LOGW(TAG, "mDNS: no service found; retry in %u ms", (unsigned)retry_ms);
|
||||||
|
vTaskDelay(retry_delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- Event Handlers --------------------
|
||||||
|
static void on_ip_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
(void)data;
|
||||||
|
|
||||||
|
if (base == IP_EVENT && id == IP_EVENT_STA_GOT_IP) {
|
||||||
|
// mDNS starten
|
||||||
|
mdns_start_if_needed();
|
||||||
|
|
||||||
|
// Optional: Discovery-Task starten, wenn enabled
|
||||||
|
if (g_discover_enabled && g_discover_task == NULL) {
|
||||||
|
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
|
||||||
|
if (ok != pdPASS) {
|
||||||
|
g_discover_task = NULL;
|
||||||
|
ESP_LOGE(TAG, "Failed to create mdns_discover task");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_wifi_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
(void)data;
|
||||||
|
|
||||||
|
if (base == WIFI_EVENT && id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||||
|
// Beim Disconnect mDNS stoppen
|
||||||
|
mdns_stop_if_running();
|
||||||
|
|
||||||
|
// Status: nicht ok (No-op in diesem Component)
|
||||||
|
set_mdns_ok(false);
|
||||||
|
|
||||||
|
// Discovery Task NICHT hart killen (kann in mdns_query hängen).
|
||||||
|
// Bei nächstem GOT_IP kann sie erneut starten; oder sie schläft und merkt g_discover_enabled später.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- Public API --------------------
|
||||||
|
esp_err_t net_mdns_autostart_init(const char *hostname, const char *instance_name)
|
||||||
|
{
|
||||||
|
// idempotent: mehrfacher Aufruf ist ok, registriert aber nur einmal Handler
|
||||||
|
if (hostname) {
|
||||||
|
strncpy(g_hostname, hostname, sizeof(g_hostname) - 1);
|
||||||
|
g_hostname[sizeof(g_hostname) - 1] = '\0';
|
||||||
|
}
|
||||||
|
if (instance_name) {
|
||||||
|
strncpy(g_instance, instance_name, sizeof(g_instance) - 1);
|
||||||
|
g_instance[sizeof(g_instance) - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_autostart_inited) {
|
||||||
|
esp_err_t e1 = esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP,
|
||||||
|
on_ip_event, NULL, &g_ip_handler);
|
||||||
|
esp_err_t e2 = esp_event_handler_instance_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED,
|
||||||
|
on_wifi_event, NULL, &g_wifi_handler);
|
||||||
|
if (e1 != ESP_OK || e2 != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to register event handlers (ip=%s wifi=%s)",
|
||||||
|
esp_err_to_name(e1), esp_err_to_name(e2));
|
||||||
|
return (e1 != ESP_OK) ? e1 : e2;
|
||||||
|
}
|
||||||
|
g_autostart_inited = true;
|
||||||
|
ESP_LOGI(TAG, "mDNS autostart initialized");
|
||||||
|
} else {
|
||||||
|
ESP_LOGD(TAG, "mDNS autostart already initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Falls IP schon vorhanden → mDNS direkt starten (+ ggf. discovery task)
|
||||||
|
if (have_sta_ip()) {
|
||||||
|
mdns_start_if_needed();
|
||||||
|
if (g_discover_enabled && g_discover_task == NULL) {
|
||||||
|
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
|
||||||
|
if (ok != pdPASS) {
|
||||||
|
g_discover_task = NULL;
|
||||||
|
ESP_LOGE(TAG, "Failed to create mdns_discover task");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool net_mdns_is_running(void)
|
||||||
|
{
|
||||||
|
return g_mdns_running;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool net_mdns_wait_started(uint32_t timeout_ms)
|
||||||
|
{
|
||||||
|
uint32_t waited = 0;
|
||||||
|
const uint32_t step = 50;
|
||||||
|
|
||||||
|
while (!g_mdns_running && waited < timeout_ms) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(step));
|
||||||
|
waited += step;
|
||||||
|
}
|
||||||
|
return g_mdns_running;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t net_mdns_add_service(const char *service, const char *proto,
|
||||||
|
uint16_t port, mdns_txt_item_t *txt, size_t txt_count)
|
||||||
|
{
|
||||||
|
if (!g_mdns_running) {
|
||||||
|
mdns_start_if_needed();
|
||||||
|
if (!g_mdns_running) return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = mdns_service_add(NULL, service, proto, port, txt, txt_count);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "mdns_service_add %s.%s:%u failed: %s",
|
||||||
|
service, proto, (unsigned)port, esp_err_to_name(err));
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "mDNS service announced: %s.%s:%u", service, proto, (unsigned)port);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
|
||||||
|
int enforce_port,
|
||||||
|
const char *txt_key, const char *txt_value,
|
||||||
|
uint32_t timeout_ms)
|
||||||
|
{
|
||||||
|
char url[96] = {0};
|
||||||
|
|
||||||
|
bool ok = net_mdns_find_service_url(service, proto, enforce_port,
|
||||||
|
txt_key, txt_value,
|
||||||
|
timeout_ms, 5,
|
||||||
|
url, sizeof(url));
|
||||||
|
if (!ok) {
|
||||||
|
ESP_LOGW(TAG, "Auto-Discover: kein Treffer für %s.%s", service, proto);
|
||||||
|
return ESP_ERR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = storage_save_service_url(url);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "Auto-Discover: URL '%s' in NVS gespeichert.", url);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool net_mdns_find_service_url(const char *service, const char *proto,
|
||||||
|
int enforce_port, const char *txt_key, const char *txt_value,
|
||||||
|
uint32_t timeout_ms, int max_results,
|
||||||
|
char *url_out, size_t url_out_size)
|
||||||
|
{
|
||||||
|
if (!service || !proto || !url_out || url_out_size < 16) return false;
|
||||||
|
|
||||||
|
if (!g_mdns_running) {
|
||||||
|
ESP_LOGW(TAG, "mDNS not running yet; waiting...");
|
||||||
|
if (!net_mdns_wait_started(3000)) {
|
||||||
|
ESP_LOGW(TAG, "mDNS still not running; abort query");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mdns_result_t *results = NULL;
|
||||||
|
esp_err_t err = mdns_query_ptr(service, proto, timeout_ms, max_results, &results);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "mdns_query_ptr error: %s", esp_err_to_name(err));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!results) {
|
||||||
|
ESP_LOGI(TAG, "mDNS query OK but no results for %s.%s", service, proto);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (mdns_result_t *r = results; r && !found; r = r->next) {
|
||||||
|
// TXT filter
|
||||||
|
bool txt_ok = true;
|
||||||
|
if (txt_key && txt_value) {
|
||||||
|
txt_ok = false;
|
||||||
|
for (int i = 0; i < r->txt_count; ++i) {
|
||||||
|
if (r->txt[i].key && r->txt[i].value &&
|
||||||
|
strcmp(r->txt[i].key, txt_key) == 0 &&
|
||||||
|
strcmp(r->txt[i].value, txt_value) == 0) {
|
||||||
|
txt_ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!txt_ok) continue;
|
||||||
|
|
||||||
|
// Optional: Instance prefix filter (nur wenn konfiguriert)
|
||||||
|
if (g_discover_cfg.require_instance_prefix && g_discover_cfg.instance_prefix[0]) {
|
||||||
|
size_t pfx_len = strlen(g_discover_cfg.instance_prefix);
|
||||||
|
if (!r->instance_name || strncmp(r->instance_name, g_discover_cfg.instance_prefix, pfx_len) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (mdns_ip_addr_t *a = r->addr; a && !found; a = a->next) {
|
||||||
|
if (a->addr.type != ESP_IPADDR_TYPE_V4) continue;
|
||||||
|
|
||||||
|
uint16_t port = r->port ? r->port : 80;
|
||||||
|
if (enforce_port > 0 && port != (uint16_t)enforce_port) port = (uint16_t)enforce_port;
|
||||||
|
|
||||||
|
snprintf(url_out, url_out_size, "http://" IPSTR ":%u",
|
||||||
|
IP2STR(&a->addr.u_addr.ip4), (unsigned)port);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "mDNS URL: %s", url_out);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mdns_query_results_free(results);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_mdns_stop(void)
|
||||||
|
{
|
||||||
|
// Discovery stoppen (soft)
|
||||||
|
g_discover_enabled = false;
|
||||||
|
|
||||||
|
// mDNS stoppen
|
||||||
|
mdns_stop_if_running();
|
||||||
|
set_mdns_ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- New Public: Discovery Retry --------------------
|
||||||
|
esp_err_t net_mdns_autodiscover_start(const net_mdns_discover_cfg_t *cfg)
|
||||||
|
{
|
||||||
|
if (!cfg || !cfg->service || !cfg->proto) return ESP_ERR_INVALID_ARG;
|
||||||
|
|
||||||
|
// config übernehmen (interne Kopie)
|
||||||
|
memset(&g_discover_cfg, 0, sizeof(g_discover_cfg));
|
||||||
|
|
||||||
|
strlcpy(g_discover_cfg.service, cfg->service, sizeof(g_discover_cfg.service));
|
||||||
|
strlcpy(g_discover_cfg.proto, cfg->proto, sizeof(g_discover_cfg.proto));
|
||||||
|
g_discover_cfg.enforce_port = cfg->enforce_port;
|
||||||
|
|
||||||
|
if (cfg->fallback_service && cfg->fallback_proto) {
|
||||||
|
strlcpy(g_discover_cfg.fallback_service, cfg->fallback_service, sizeof(g_discover_cfg.fallback_service));
|
||||||
|
strlcpy(g_discover_cfg.fallback_proto, cfg->fallback_proto, sizeof(g_discover_cfg.fallback_proto));
|
||||||
|
g_discover_cfg.fallback_port = cfg->fallback_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg->txt_key && cfg->txt_value) {
|
||||||
|
strlcpy(g_discover_cfg.txt_key, cfg->txt_key, sizeof(g_discover_cfg.txt_key));
|
||||||
|
strlcpy(g_discover_cfg.txt_value, cfg->txt_value, sizeof(g_discover_cfg.txt_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_discover_cfg.query_timeout_ms = (cfg->query_timeout_ms ? cfg->query_timeout_ms : 2000);
|
||||||
|
g_discover_cfg.retry_interval_ms = (cfg->retry_interval_ms ? cfg->retry_interval_ms : 60000);
|
||||||
|
g_discover_cfg.max_results = (cfg->max_results ? cfg->max_results : 5);
|
||||||
|
|
||||||
|
if (cfg->instance_prefix && cfg->instance_prefix[0]) {
|
||||||
|
strlcpy(g_discover_cfg.instance_prefix, cfg->instance_prefix, sizeof(g_discover_cfg.instance_prefix));
|
||||||
|
g_discover_cfg.require_instance_prefix = cfg->require_instance_prefix;
|
||||||
|
} else {
|
||||||
|
g_discover_cfg.require_instance_prefix = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable
|
||||||
|
g_discover_enabled = true;
|
||||||
|
set_mdns_ok(false);
|
||||||
|
|
||||||
|
// Wenn wir schon IP haben: Task sofort starten, sonst wird er bei GOT_IP gestartet
|
||||||
|
if (have_sta_ip()) {
|
||||||
|
mdns_start_if_needed();
|
||||||
|
if (g_discover_task == NULL) {
|
||||||
|
BaseType_t ok = xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, &g_discover_task);
|
||||||
|
if (ok != pdPASS) {
|
||||||
|
g_discover_task = NULL;
|
||||||
|
ESP_LOGE(TAG, "Failed to create mdns_discover task");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_mdns_autodiscover_stop(void)
|
||||||
|
{
|
||||||
|
g_discover_enabled = false;
|
||||||
|
// Task beendet sich selbst (kein hartes Kill)
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"sen5x_i2c.c"
|
||||||
|
"sensirion_common.c"
|
||||||
|
"sensirion_i2c.c"
|
||||||
|
"sensirion_i2c_hal.c"
|
||||||
|
"i2cdev.c"
|
||||||
|
"sen5x_app.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"."
|
||||||
|
REQUIRES
|
||||||
|
driver
|
||||||
|
freertos
|
||||||
|
log
|
||||||
|
net_influx
|
||||||
|
eez_gui
|
||||||
|
)
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h" // bleibt drin (Header-Kompat / ggf. künftig wieder genutzt)
|
||||||
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sensirion_i2c_hal.h"
|
#include "sensirion_i2c_hal.h"
|
||||||
@@ -20,23 +20,22 @@
|
|||||||
#include <math.h> // NAN, isfinite, lround
|
#include <math.h> // NAN, isfinite, lround
|
||||||
#include "vars.h"
|
#include "vars.h"
|
||||||
|
|
||||||
// i2cdev API (aus i2cdev.c)
|
|
||||||
esp_err_t i2cdev_init(void);
|
|
||||||
esp_err_t i2cdev_done(void);
|
|
||||||
|
|
||||||
static const char* TAG = "sen5x_app";
|
static const char* TAG = "sen5x_app";
|
||||||
|
|
||||||
/* ====================== Konfiguration ====================== */
|
/* ====================== Konfiguration ====================== */
|
||||||
#define SEN5X_QUEUE_LEN 16 // Puffergröße für Samples
|
|
||||||
#define SEN5X_PROD_STACK 4096
|
#define SEN5X_PROD_STACK 4096
|
||||||
#define SEN5X_CONS_STACK 6144
|
|
||||||
#define SEN5X_PROD_PRIO 6 // Producer leicht höher priorisiert
|
#define SEN5X_PROD_PRIO 6 // Producer leicht höher priorisiert
|
||||||
#define SEN5X_CONS_PRIO 5
|
|
||||||
|
|
||||||
#define INFLUX_INIT_RETRY_MS 1000 // Retry-Intervall bis Influx init
|
// Influx worker runtime (läuft in net_influx.c)
|
||||||
#define INFLUX_FAILS_REDISCOVER 5 // Nach X Fehlern: Re-Init/Rediscovery
|
#define INFLUX_QUEUE_LEN 16
|
||||||
|
#define INFLUX_TASK_STACK 6144
|
||||||
|
#define INFLUX_TASK_PRIO 5
|
||||||
|
|
||||||
|
#define INFLUX_INIT_RETRY_MS 1000
|
||||||
|
#define INFLUX_FAILS_REDISCOVER 5
|
||||||
#define INFLUX_BACKOFF_START_MS 2000
|
#define INFLUX_BACKOFF_START_MS 2000
|
||||||
#define INFLUX_BACKOFF_MAX_MS 300000
|
#define INFLUX_BACKOFF_MAX_MS 300000
|
||||||
|
#define INFLUX_HTTP_TIMEOUT_MS 3000
|
||||||
|
|
||||||
/* ====================== Typen & State ====================== */
|
/* ====================== Typen & State ====================== */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -47,11 +46,9 @@ typedef struct {
|
|||||||
|
|
||||||
static bool g_inited = false;
|
static bool g_inited = false;
|
||||||
static bool g_run = false;
|
static bool g_run = false;
|
||||||
static QueueHandle_t g_queue = NULL;
|
|
||||||
static TaskHandle_t g_task_prod = NULL;
|
static TaskHandle_t g_task_prod = NULL;
|
||||||
static TaskHandle_t g_task_cons = NULL;
|
|
||||||
|
|
||||||
// Nur vom Consumer benutzt:
|
// App-Context
|
||||||
static char* g_device_tag = NULL; // z.B. "device=xyz"
|
static char* g_device_tag = NULL; // z.B. "device=xyz"
|
||||||
|
|
||||||
/* ====================== Helfer ====================== */
|
/* ====================== Helfer ====================== */
|
||||||
@@ -119,6 +116,26 @@ static int16_t sen5x_read_measured_pm_values_float(float* pm1, float* pm2,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ====================== App-Context: Device Tag ====================== */
|
||||||
|
static esp_err_t make_device_tag_once(void) {
|
||||||
|
if (g_device_tag) return ESP_OK;
|
||||||
|
|
||||||
|
char* dev = NULL;
|
||||||
|
if (storage_load_device_name(&dev) && dev && dev[0]) {
|
||||||
|
size_t need = strlen("device=") + strlen(dev) + 1;
|
||||||
|
g_device_tag = (char*)malloc(need);
|
||||||
|
if (!g_device_tag) {
|
||||||
|
if (dev) free(dev);
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
snprintf(g_device_tag, need, "device=%s", dev);
|
||||||
|
free(dev);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
g_device_tag = strdup("device=unknown");
|
||||||
|
return g_device_tag ? ESP_OK : ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* ====================== Producer-Task ====================== */
|
/* ====================== Producer-Task ====================== */
|
||||||
static void sen5x_task_producer(void* arg) {
|
static void sen5x_task_producer(void* arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
@@ -186,12 +203,36 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
||||||
set_var_pm1p0(buf);
|
set_var_pm1p0(buf);
|
||||||
|
|
||||||
// Non-blocking enqueue; bei voller Queue: ältestes raus, neues rein
|
/* === Influx submit (generisch, variabel viele Felder) === */
|
||||||
if (xQueueSend(g_queue, &s, 0) != pdPASS) {
|
const double pm1 = (s.pm1p0 == 0xFFFF) ? NAN : ((double)s.pm1p0 / 10.0);
|
||||||
sen5x_sample_t dump;
|
const double pm2_5 = (s.pm2p5 == 0xFFFF) ? NAN : ((double)s.pm2p5 / 10.0);
|
||||||
(void)xQueueReceive(g_queue, &dump, 0); // drop oldest
|
const double pm4 = (s.pm4p0 == 0xFFFF) ? NAN : ((double)s.pm4p0 / 10.0);
|
||||||
(void)xQueueSend(g_queue, &s, 0);
|
const double pm10 = (s.pm10p0 == 0xFFFF) ? NAN : ((double)s.pm10p0 / 10.0);
|
||||||
}
|
const double voc = (s.voc_idx == 0x7FFF) ? NAN : ((double)s.voc_idx / 10.0);
|
||||||
|
const double nox = (s.nox_idx == 0x7FFF) ? NAN : ((double)s.nox_idx / 10.0);
|
||||||
|
const double temp = (double)s.temp_c;
|
||||||
|
const double rh = (double)s.rh_pct;
|
||||||
|
|
||||||
|
net_influx_field_t f[] = {
|
||||||
|
{ .key="pm1", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm1 },
|
||||||
|
{ .key="pm2_5", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm2_5 },
|
||||||
|
{ .key="pm4", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm4 },
|
||||||
|
{ .key="pm10", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=pm10 },
|
||||||
|
{ .key="temp", .type=NET_INFLUX_F_FLOAT, .precision=3, .v.f=temp },
|
||||||
|
{ .key="rh", .type=NET_INFLUX_F_FLOAT, .precision=3, .v.f=rh },
|
||||||
|
{ .key="voc", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=voc },
|
||||||
|
{ .key="nox", .type=NET_INFLUX_F_FLOAT, .precision=1, .v.f=nox },
|
||||||
|
};
|
||||||
|
|
||||||
|
net_influx_point_t p = {
|
||||||
|
.measurement = "air",
|
||||||
|
.tags = g_device_tag ? g_device_tag : "device=unknown",
|
||||||
|
.ts_ms = 0, // Serverzeit
|
||||||
|
.fields = f,
|
||||||
|
.num_fields = sizeof(f) / sizeof(f[0]),
|
||||||
|
};
|
||||||
|
|
||||||
|
(void)net_influx_submit_point(&p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,159 +240,7 @@ static void sen5x_task_producer(void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Producer stopping.");
|
ESP_LOGI(TAG, "Producer stopping.");
|
||||||
vTaskDelete(NULL);
|
g_task_prod = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* ====================== Consumer-Task ====================== */
|
|
||||||
static esp_err_t make_device_tag_once(void) {
|
|
||||||
if (g_device_tag) return ESP_OK;
|
|
||||||
|
|
||||||
char* dev = NULL;
|
|
||||||
if (storage_load_device_name(&dev) && dev && dev[0]) {
|
|
||||||
size_t need = strlen("device=") + strlen(dev) + 1;
|
|
||||||
g_device_tag = (char*)malloc(need);
|
|
||||||
if (!g_device_tag) {
|
|
||||||
if (dev) free(dev);
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
snprintf(g_device_tag, need, "device=%s", dev);
|
|
||||||
free(dev);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
g_device_tag = strdup("device=unknown");
|
|
||||||
return g_device_tag ? ESP_OK : ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool influx_init_blocking(void) {
|
|
||||||
// Warte/Retry bis Influx-Konfig aus NVS (oder Discovery via net_influx_* intern) bereit ist
|
|
||||||
while (g_run) {
|
|
||||||
if (net_influx_init_from_nvs(NULL, 3000) == ESP_OK) {
|
|
||||||
if (make_device_tag_once() == ESP_OK) {
|
|
||||||
ESP_LOGI(TAG, "Influx ready, device tag: %s", g_device_tag);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Device-Tag allokation fehlgeschlagen");
|
|
||||||
return false; // fatal → Task kann enden
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "Influx nicht bereit – retry in %d ms", INFLUX_INIT_RETRY_MS);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(INFLUX_INIT_RETRY_MS));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool influx_reinit_with_backoff(uint32_t* backoff_ms) {
|
|
||||||
if (!backoff_ms) return false;
|
|
||||||
uint32_t wait_ms = *backoff_ms;
|
|
||||||
if (wait_ms == 0) wait_ms = INFLUX_BACKOFF_START_MS;
|
|
||||||
|
|
||||||
ESP_LOGW(TAG, "Re-Init Influx in %u ms", (unsigned)wait_ms);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(wait_ms));
|
|
||||||
|
|
||||||
bool ok = (net_influx_init_from_nvs(NULL, 3000) == ESP_OK);
|
|
||||||
if (ok) {
|
|
||||||
ESP_LOGI(TAG, "Influx Re-Init OK");
|
|
||||||
*backoff_ms = INFLUX_BACKOFF_START_MS;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exponentielles Backoff bis Max
|
|
||||||
if (wait_ms < INFLUX_BACKOFF_MAX_MS) {
|
|
||||||
uint32_t next = wait_ms * 2;
|
|
||||||
*backoff_ms = (next > INFLUX_BACKOFF_MAX_MS) ? INFLUX_BACKOFF_MAX_MS : next;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hilfsfunktion: Felder-String ohne NaNs bauen (Influx lehnt NaN/Inf ab) */
|
|
||||||
static size_t append_field(char* dst, size_t cap, size_t pos, const char* key, double val, int precision) {
|
|
||||||
if (!isfinite(val)) return pos; // skip NaN/Inf
|
|
||||||
int n;
|
|
||||||
if (pos > 0) {
|
|
||||||
n = snprintf(dst + pos, (cap > pos) ? (cap - pos) : 0, ",");
|
|
||||||
pos += (n > 0) ? n : 0;
|
|
||||||
}
|
|
||||||
char fmt[16];
|
|
||||||
// z.B. "%.1f" oder "%.3f"
|
|
||||||
snprintf(fmt, sizeof(fmt), "%%s=%%.%df", precision);
|
|
||||||
n = snprintf(dst + pos, (cap > pos) ? (cap - pos) : 0, fmt, key, val);
|
|
||||||
pos += (n > 0) ? n : 0;
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sen5x_task_consumer(void* arg) {
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Consumer started.");
|
|
||||||
|
|
||||||
if (!influx_init_blocking()) {
|
|
||||||
ESP_LOGE(TAG, "Consumer beendet (Influx init fatal gescheitert).");
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fail_count = 0;
|
|
||||||
uint32_t backoff_ms = INFLUX_BACKOFF_START_MS;
|
|
||||||
|
|
||||||
for (; g_run; ) {
|
|
||||||
sen5x_sample_t s;
|
|
||||||
if (xQueueReceive(g_queue, &s, portMAX_DELAY) != pdTRUE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skaliere (physikalische Einheiten)
|
|
||||||
const double pm1 = (s.pm1p0 == 0xFFFF) ? NAN : ((double)s.pm1p0 / 10.0);
|
|
||||||
const double pm2_5 = (s.pm2p5 == 0xFFFF) ? NAN : ((double)s.pm2p5 / 10.0);
|
|
||||||
const double pm4 = (s.pm4p0 == 0xFFFF) ? NAN : ((double)s.pm4p0 / 10.0);
|
|
||||||
const double pm10 = (s.pm10p0 == 0xFFFF) ? NAN : ((double)s.pm10p0 / 10.0);
|
|
||||||
const double voc = (s.voc_idx == 0x7FFF) ? NAN : ((double)s.voc_idx / 10.0);
|
|
||||||
const double nox = (s.nox_idx == 0x7FFF) ? NAN : ((double)s.nox_idx / 10.0);
|
|
||||||
const double temp = (double)s.temp_c;
|
|
||||||
const double rh = (double)s.rh_pct;
|
|
||||||
|
|
||||||
// Felder dynamisch ohne NaNs zusammenbauen
|
|
||||||
char fields[256];
|
|
||||||
size_t pos = 0;
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "pm1", pm1, 1);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "pm2_5", pm2_5, 1);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "pm4", pm4, 1);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "pm10", pm10, 1);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "temp", temp, 3);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "rh", rh, 3);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "voc", voc, 1);
|
|
||||||
pos = append_field(fields, sizeof(fields), pos, "nox", nox, 1);
|
|
||||||
|
|
||||||
if (pos == 0) {
|
|
||||||
// Nichts valides → überspringen
|
|
||||||
ESP_LOGW(TAG, "Skipping write: no finite fields.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fields[(pos < sizeof(fields)) ? pos : sizeof(fields) - 1] = '\0';
|
|
||||||
|
|
||||||
// Ohne Timestamp (0) → Influx vergibt Serverzeit. precision=ms im HTTP-Client ist ok.
|
|
||||||
esp_err_t e = net_influx_write_fields(
|
|
||||||
"air",
|
|
||||||
g_device_tag ? g_device_tag : "device=unknown",
|
|
||||||
0 /* ts_ms */,
|
|
||||||
"%s",
|
|
||||||
fields
|
|
||||||
);
|
|
||||||
|
|
||||||
if (e == ESP_OK) {
|
|
||||||
if (fail_count) ESP_LOGI(TAG, "Influx write recovered.");
|
|
||||||
fail_count = 0;
|
|
||||||
backoff_ms = INFLUX_BACKOFF_START_MS;
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "Influx write failed: %s", esp_err_to_name(e));
|
|
||||||
if (++fail_count >= INFLUX_FAILS_REDISCOVER) {
|
|
||||||
(void)influx_reinit_with_backoff(&backoff_ms);
|
|
||||||
fail_count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Consumer stopping.");
|
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +255,7 @@ esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) {
|
|||||||
ESP_LOGI(TAG, "Initializing SEN5x app...");
|
ESP_LOGI(TAG, "Initializing SEN5x app...");
|
||||||
|
|
||||||
// 1) I2C-Subsystem
|
// 1) I2C-Subsystem
|
||||||
CHECK_ESP_OR_RET(i2cdev_init());
|
|
||||||
|
|
||||||
// 2) HAL-Konfiguration
|
// 2) HAL-Konfiguration
|
||||||
struct esp32_i2c_config hal_cfg = {
|
struct esp32_i2c_config hal_cfg = {
|
||||||
@@ -388,15 +277,22 @@ esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) {
|
|||||||
CHECK_SEN_OR_RET(sen5x_start_measurement());
|
CHECK_SEN_OR_RET(sen5x_start_measurement());
|
||||||
ESP_LOGI(TAG, "Measurement started.");
|
ESP_LOGI(TAG, "Measurement started.");
|
||||||
|
|
||||||
// 5) Queue + Run-Flag
|
// 5) Device Tag (App-Kontext)
|
||||||
g_queue = xQueueCreate(SEN5X_QUEUE_LEN, sizeof(sen5x_sample_t));
|
CHECK_ESP_OR_RET(make_device_tag_once());
|
||||||
if (!g_queue) {
|
|
||||||
ESP_LOGE(TAG, "xQueueCreate failed");
|
// 6) Influx Worker starten (Influx-spezifische Init/Retry/Backoff läuft intern)
|
||||||
sen5x_stop_measurement();
|
net_influx_runtime_cfg_t rt = {
|
||||||
sensirion_i2c_hal_free();
|
.queue_len = INFLUX_QUEUE_LEN,
|
||||||
i2cdev_done();
|
.task_stack = INFLUX_TASK_STACK,
|
||||||
return ESP_ERR_NO_MEM;
|
.task_prio = INFLUX_TASK_PRIO,
|
||||||
}
|
.init_retry_ms = INFLUX_INIT_RETRY_MS,
|
||||||
|
.backoff_start_ms = INFLUX_BACKOFF_START_MS,
|
||||||
|
.backoff_max_ms = INFLUX_BACKOFF_MAX_MS,
|
||||||
|
.fails_before_reinit = INFLUX_FAILS_REDISCOVER,
|
||||||
|
.ca_cert_pem_opt = NULL,
|
||||||
|
.http_timeout_ms = INFLUX_HTTP_TIMEOUT_MS,
|
||||||
|
};
|
||||||
|
CHECK_ESP_OR_RET(net_influx_start(&rt));
|
||||||
|
|
||||||
g_run = true;
|
g_run = true;
|
||||||
g_inited = true;
|
g_inited = true;
|
||||||
@@ -408,42 +304,38 @@ void sen5x_app_deinit(void) {
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "Deinitializing SEN5x app...");
|
ESP_LOGI(TAG, "Deinitializing SEN5x app...");
|
||||||
|
|
||||||
// Tasks stoppen
|
|
||||||
g_run = false;
|
g_run = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < 50 && g_task_prod; i++) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
|
||||||
if (g_task_prod) {
|
if (g_task_prod) {
|
||||||
vTaskDelete(g_task_prod);
|
ESP_LOGW(TAG, "Producer did not stop in time; skip sen5x_stop_measurement/HAL free");
|
||||||
g_task_prod = NULL;
|
// Hier NICHT sen5x_stop_measurement() / HAL free, weil Task evtl. noch I2C nutzt
|
||||||
}
|
return;
|
||||||
if (g_task_cons) {
|
|
||||||
vTaskDelete(g_task_cons);
|
|
||||||
g_task_cons = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue
|
net_influx_stop();
|
||||||
if (g_queue) {
|
|
||||||
vQueueDelete(g_queue);
|
|
||||||
g_queue = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Influx Tag
|
|
||||||
if (g_device_tag) {
|
if (g_device_tag) {
|
||||||
free(g_device_tag);
|
free(g_device_tag);
|
||||||
g_device_tag = NULL;
|
g_device_tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sensor stoppen & HAL freigeben
|
|
||||||
sen5x_stop_measurement();
|
sen5x_stop_measurement();
|
||||||
sensirion_i2c_hal_free();
|
sensirion_i2c_hal_free();
|
||||||
i2cdev_done();
|
|
||||||
|
// i2cdev_done(); // NICHT hier, da Bus global genutzt wird
|
||||||
|
|
||||||
g_inited = false;
|
g_inited = false;
|
||||||
ESP_LOGI(TAG, "SEN5x app deinitialized.");
|
ESP_LOGI(TAG, "SEN5x app deinitialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kompatibilität zur bisherigen main.c:
|
* Kompatibilität zur bisherigen main.c:
|
||||||
* Diese Task fungiert nun als "Launcher": startet Producer & Consumer und beendet sich dann.
|
* Diese Task fungiert nun als "Launcher": startet Producer und beendet sich dann.
|
||||||
* In main.c bleibt der Aufruf von xTaskCreate(sen5x_app_task, ...) unverändert.
|
* In main.c bleibt der Aufruf von xTaskCreate(sen5x_app_task, ...) unverändert.
|
||||||
*/
|
*/
|
||||||
void sen5x_app_task(void* arg) {
|
void sen5x_app_task(void* arg) {
|
||||||
@@ -455,20 +347,14 @@ void sen5x_app_task(void* arg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Producer / Consumer starten
|
// Producer starten
|
||||||
if (xTaskCreate(sen5x_task_producer, "sen5x_prod", SEN5X_PROD_STACK, NULL, SEN5X_PROD_PRIO, &g_task_prod) != pdPASS) {
|
if (xTaskCreate(sen5x_task_producer, "sen5x_prod",
|
||||||
|
SEN5X_PROD_STACK, NULL, SEN5X_PROD_PRIO, &g_task_prod) != pdPASS) {
|
||||||
ESP_LOGE(TAG, "Failed to create producer task");
|
ESP_LOGE(TAG, "Failed to create producer task");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (xTaskCreate(sen5x_task_consumer, "sen5x_cons", SEN5X_CONS_STACK, NULL, SEN5X_CONS_PRIO, &g_task_cons) != pdPASS) {
|
|
||||||
ESP_LOGE(TAG, "Failed to create consumer task");
|
|
||||||
vTaskDelete(g_task_prod);
|
|
||||||
g_task_prod = NULL;
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Launcher done (producer+consumer started).");
|
ESP_LOGI(TAG, "Launcher done (producer started).");
|
||||||
vTaskDelete(NULL); // Launcher beendet sich selbst
|
vTaskDelete(NULL); // Launcher beendet sich selbst
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
// File: sensirion_i2c_hal.c
|
||||||
|
|
||||||
|
#include "sensirion_i2c_hal.h"
|
||||||
|
#include "sensirion_common.h"
|
||||||
|
#include "sensirion_config.h"
|
||||||
|
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "sensirion_i2c_esp32_config.h"
|
||||||
|
|
||||||
|
static const char* TAG = "sensirion_i2c_hal";
|
||||||
|
|
||||||
|
#define SLEEP_MS(ms) vTaskDelay(((ms) + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sensirion HAL uses int8_t return codes:
|
||||||
|
* - 0 (NO_ERROR) on success
|
||||||
|
* - !=0 on failure
|
||||||
|
*
|
||||||
|
* sensirion_common.h defines only NO_ERROR and NOT_IMPLEMENTED_ERROR,
|
||||||
|
* so we provide one stable generic error that fits in int8_t.
|
||||||
|
*/
|
||||||
|
#define SENSIRION_I2C_HAL_ERROR ((int8_t)-1)
|
||||||
|
|
||||||
|
// Global (single) i2cdev device context
|
||||||
|
static i2c_dev_t dev = {0};
|
||||||
|
static struct esp32_i2c_config i2c_cfg = {0};
|
||||||
|
static esp_err_t i2c_ok = ESP_OK;
|
||||||
|
|
||||||
|
static int8_t sensirion_map_esp_err(esp_err_t err) {
|
||||||
|
return (err == ESP_OK) ? (int8_t)NO_ERROR : SENSIRION_I2C_HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select the current i2c bus by index.
|
||||||
|
* Optional for single-bus setups.
|
||||||
|
*/
|
||||||
|
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx) {
|
||||||
|
/*
|
||||||
|
* NOTE:
|
||||||
|
* - This only switches the I2C port number.
|
||||||
|
* - If "bus_idx" implies different pins/frequency, update i2c_cfg accordingly
|
||||||
|
* and call sensirion_i2c_hal_init() again.
|
||||||
|
*/
|
||||||
|
dev.port = (i2c_port_t)bus_idx;
|
||||||
|
i2c_cfg.port = (i2c_port_t)bus_idx;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Selected I2C bus index/port: %u", (unsigned)bus_idx);
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t sensirion_i2c_config_esp32(struct esp32_i2c_config* cfg) {
|
||||||
|
if (cfg == NULL) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
memcpy(&i2c_cfg, cfg, sizeof(*cfg));
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t sensirion_i2c_esp32_ok(void) {
|
||||||
|
return i2c_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize all hard- and software components that are needed for the I2C
|
||||||
|
* communication.
|
||||||
|
*/
|
||||||
|
void sensirion_i2c_hal_init(void) {
|
||||||
|
memset(&dev, 0, sizeof(dev));
|
||||||
|
|
||||||
|
// Minimal sanity check
|
||||||
|
if (i2c_cfg.freq == 0) {
|
||||||
|
ESP_LOGE(TAG, "Invalid I2C frequency: 0 Hz");
|
||||||
|
i2c_ok = ESP_ERR_INVALID_ARG;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// i2cdev supports 7-bit and 10-bit; Sensirion drivers use 7-bit addresses.
|
||||||
|
dev.addr_bit_len = I2C_ADDR_BIT_LEN_7;
|
||||||
|
|
||||||
|
dev.port = i2c_cfg.port;
|
||||||
|
|
||||||
|
// Pins: i2cdev supports -1 meaning "use Kconfig default"
|
||||||
|
dev.cfg.sda_io_num = i2c_cfg.sda;
|
||||||
|
dev.cfg.scl_io_num = i2c_cfg.scl;
|
||||||
|
|
||||||
|
dev.cfg.sda_pullup_en = i2c_cfg.sda_pullup;
|
||||||
|
dev.cfg.scl_pullup_en = i2c_cfg.scl_pullup;
|
||||||
|
|
||||||
|
dev.cfg.master.clk_speed = (uint32_t)i2c_cfg.freq;
|
||||||
|
|
||||||
|
esp_err_t err = i2c_dev_create_mutex(&dev);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG,
|
||||||
|
"Sensirion I2C HAL ready. Port=%d SDA=%d SCL=%d Freq=%" PRIu32 " Hz",
|
||||||
|
(int)i2c_cfg.port, (int)i2c_cfg.sda, (int)i2c_cfg.scl, (uint32_t)i2c_cfg.freq);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG,
|
||||||
|
"Sensirion I2C HAL init error. Port=%d SDA=%d SCL=%d (err=%s)",
|
||||||
|
(int)i2c_cfg.port, (int)i2c_cfg.sda, (int)i2c_cfg.scl, esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_ok = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release all resources initialized by sensirion_i2c_hal_init().
|
||||||
|
*/
|
||||||
|
void sensirion_i2c_hal_free(void) {
|
||||||
|
esp_err_t err = i2c_dev_delete_mutex(&dev);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "i2c_dev_delete_mutex failed: %s", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute one read transaction on the I2C bus.
|
||||||
|
*
|
||||||
|
* @returns 0 on success, error code otherwise
|
||||||
|
*/
|
||||||
|
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
|
||||||
|
if (count > 0 && data == NULL) {
|
||||||
|
return SENSIRION_I2C_HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.addr = address;
|
||||||
|
|
||||||
|
esp_err_t err = i2c_dev_take_mutex(&dev);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "take_mutex failed: %s", esp_err_to_name(err));
|
||||||
|
i2c_ok = err;
|
||||||
|
return sensirion_map_esp_err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i2c_dev_read(&dev, NULL, 0, data, (size_t)count);
|
||||||
|
|
||||||
|
esp_err_t give_err = i2c_dev_give_mutex(&dev);
|
||||||
|
if (give_err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "give_mutex failed: %s", esp_err_to_name(give_err));
|
||||||
|
i2c_ok = give_err;
|
||||||
|
return sensirion_map_esp_err(give_err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "I2C READ failed addr=0x%02x len=%u: %s",
|
||||||
|
address, (unsigned)count, esp_err_to_name(err));
|
||||||
|
i2c_ok = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sensirion_map_esp_err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute one write transaction on the I2C bus.
|
||||||
|
*
|
||||||
|
* @returns 0 on success, error code otherwise
|
||||||
|
*/
|
||||||
|
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data, uint16_t count) {
|
||||||
|
if (count > 0 && data == NULL) {
|
||||||
|
return SENSIRION_I2C_HAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.addr = address;
|
||||||
|
|
||||||
|
esp_err_t err = i2c_dev_take_mutex(&dev);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "take_mutex failed: %s", esp_err_to_name(err));
|
||||||
|
i2c_ok = err;
|
||||||
|
return sensirion_map_esp_err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i2c_dev_write(&dev, NULL, 0, data, (size_t)count);
|
||||||
|
|
||||||
|
esp_err_t give_err = i2c_dev_give_mutex(&dev);
|
||||||
|
if (give_err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "give_mutex failed: %s", esp_err_to_name(give_err));
|
||||||
|
i2c_ok = give_err;
|
||||||
|
return sensirion_map_esp_err(give_err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "I2C WRITE failed addr=0x%02x len=%u: %s",
|
||||||
|
address, (unsigned)count, esp_err_to_name(err));
|
||||||
|
i2c_ok = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sensirion_map_esp_err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sleep for a given number of microseconds.
|
||||||
|
* Despite the unit, a <10 millisecond precision is sufficient.
|
||||||
|
*/
|
||||||
|
void sensirion_i2c_hal_sleep_usec(uint32_t useconds) {
|
||||||
|
// at-least semantics: ceil to milliseconds
|
||||||
|
uint32_t ms = (useconds + 999U) / 1000U;
|
||||||
|
if (ms == 0 && useconds > 0) {
|
||||||
|
ms = 1;
|
||||||
|
}
|
||||||
|
SLEEP_MS(ms);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/storage.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
nvs_flash
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/sys_status.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
)
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// File: firmware/components/sys_status/include/sys_status.h
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
#include "sys_status.h"
|
// Field: firmware/components/sys_status/src/sys_status.c
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
|
|
||||||
|
#include "sys_status.h"
|
||||||
|
|
||||||
static EventGroupHandle_t s_status_group = NULL;
|
static EventGroupHandle_t s_status_group = NULL;
|
||||||
|
|
||||||
void sys_status_init(void)
|
void sys_status_init(void)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS
|
||||||
|
"src/wifi_mgr.c"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"include"
|
||||||
|
REQUIRES
|
||||||
|
esp_wifi
|
||||||
|
esp_event
|
||||||
|
esp_netif
|
||||||
|
esp_timer
|
||||||
|
lwip
|
||||||
|
storage
|
||||||
|
net_mdns
|
||||||
|
sys_status
|
||||||
|
dns_captive
|
||||||
|
)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialisiert NVS, Netif, Eventloop, Wi-Fi, registriert Event-Handler und legt den AP-Auto-Off-Timer an.
|
||||||
|
void wifi_mgr_init(void);
|
||||||
|
|
||||||
|
// Startet AP+STA, HTTP-Server und DNS-Server, und stößt ggf. eine STA-Verbindung an.
|
||||||
|
void wifi_mgr_start(void);
|
||||||
|
|
||||||
|
// vorhandene Funktionen, die du schon hattest
|
||||||
|
bool wifi_mgr_load_sta_creds(char **out_ssid, char **out_pass);
|
||||||
|
void wifi_mgr_save_sta_creds_and_reconnect(const char* ssid, const char* pass);
|
||||||
|
void wifi_mgr_save_device_info(const char* devicename,
|
||||||
|
const char* token,
|
||||||
|
const char* bucket,
|
||||||
|
const char* org);
|
||||||
|
|
||||||
|
// NEU: Getter für main.c
|
||||||
|
EventGroupHandle_t wifi_mgr_get_event_group(void);
|
||||||
|
EventBits_t wifi_mgr_evt_sta_got_ip(void);
|
||||||
|
EventBits_t wifi_mgr_evt_sta_fail(void);
|
||||||
|
esp_netif_t *wifi_mgr_get_ap_netif(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -17,15 +17,11 @@
|
|||||||
|
|
||||||
#include "lwip/netdb.h"
|
#include "lwip/netdb.h"
|
||||||
|
|
||||||
#include "http_portal.h"
|
|
||||||
#include "wifi_mgr.h"
|
#include "wifi_mgr.h"
|
||||||
#include "storage.h" // NVS-Zugriffe
|
#include "storage.h"
|
||||||
#include "net_mdns.h"
|
#include "net_mdns.h"
|
||||||
#include "sys_status.h"
|
#include "sys_status.h"
|
||||||
|
#include "dns_captive.h"
|
||||||
// Captive-DNS ist in http_portal.c implementiert:
|
|
||||||
void dns_captive_start(void);
|
|
||||||
void dns_captive_stop(void);
|
|
||||||
|
|
||||||
// ---------- Konfig ----------
|
// ---------- Konfig ----------
|
||||||
#define SOFTAP_SSID "nanoPSX"
|
#define SOFTAP_SSID "nanoPSX"
|
||||||
@@ -236,8 +232,6 @@ static void wifi_event_handler(void* arg, esp_event_base_t base, int32_t id, voi
|
|||||||
ESP_LOGI(TAG, "STA got IP: " IPSTR, IP2STR(&e->ip_info.ip));
|
ESP_LOGI(TAG, "STA got IP: " IPSTR, IP2STR(&e->ip_info.ip));
|
||||||
xEventGroupSetBits(wifi_events, EVT_STA_GOTIP);
|
xEventGroupSetBits(wifi_events, EVT_STA_GOTIP);
|
||||||
|
|
||||||
xTaskCreate(mdns_discover_task, "mdns_discover", 3072, NULL, 4, NULL);
|
|
||||||
|
|
||||||
if (ap_off_timer) {
|
if (ap_off_timer) {
|
||||||
if (esp_timer_is_active(ap_off_timer)) esp_timer_stop(ap_off_timer);
|
if (esp_timer_is_active(ap_off_timer)) esp_timer_stop(ap_off_timer);
|
||||||
ESP_ERROR_CHECK(esp_timer_start_once(ap_off_timer, 10 * 1000 * 1000)); // 10 s
|
ESP_ERROR_CHECK(esp_timer_start_once(ap_off_timer, 10 * 1000 * 1000)); // 10 s
|
||||||
@@ -304,8 +298,6 @@ static void wifi_start_ap_sta(void) {
|
|||||||
|
|
||||||
// ---------- Öffentliche API ----------
|
// ---------- Öffentliche API ----------
|
||||||
void wifi_mgr_init(void) {
|
void wifi_mgr_init(void) {
|
||||||
// NVS (neu über storage)
|
|
||||||
ESP_ERROR_CHECK(storage_init());
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
@@ -326,16 +318,24 @@ void wifi_mgr_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wifi_mgr_start(void) {
|
void wifi_mgr_start(void) {
|
||||||
// AP+STA hochfahren
|
|
||||||
wifi_start_ap_sta();
|
wifi_start_ap_sta();
|
||||||
|
ESP_LOGI(TAG, "WiFi AP+STA gestartet.");
|
||||||
|
}
|
||||||
|
|
||||||
// HTTP-Portal starten (erzwingt Captive bis Save, s. http_portal.c)
|
EventGroupHandle_t wifi_mgr_get_event_group(void) {
|
||||||
ESP_ERROR_CHECK(portal_http_start(wifi_events, EVT_STA_GOTIP, EVT_STA_FAIL, SOFTAP_SSID));
|
return wifi_events;
|
||||||
|
}
|
||||||
|
|
||||||
// DNS/Captive starten
|
EventBits_t wifi_mgr_evt_sta_got_ip(void) {
|
||||||
(void)dns_captive_start();
|
return EVT_STA_GOTIP;
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Bereit. Verbinde dich mit '%s' und öffne beliebige Seite – das Portal erscheint.", SOFTAP_SSID);
|
EventBits_t wifi_mgr_evt_sta_fail(void) {
|
||||||
|
return EVT_STA_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_netif_t *wifi_mgr_get_ap_netif(void) {
|
||||||
|
return netif_ap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Hilfsfunktionen ----------
|
// ---------- Hilfsfunktionen ----------
|
||||||
@@ -351,31 +351,3 @@ static void ap_set_dhcp_dns_to_self(void) {
|
|||||||
&ip.ip, sizeof(ip.ip));
|
&ip.ip, sizeof(ip.ip));
|
||||||
esp_netif_dhcps_start(netif_ap);
|
esp_netif_dhcps_start(netif_ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task für mDNS-Discover ---
|
|
||||||
static void mdns_discover_task(void *arg) {
|
|
||||||
// Start/ensure mDNS läuft
|
|
||||||
(void)net_mdns_autostart_init(NULL, NULL);
|
|
||||||
|
|
||||||
const TickType_t kDelay = pdMS_TO_TICKS(60000); // 60 s
|
|
||||||
for (;;) {
|
|
||||||
// Erst offizieller Service, dann Fallback auf HTTP:8086
|
|
||||||
esp_err_t err = net_mdns_autodiscover_and_store("_influxdb2", "_tcp", -1,
|
|
||||||
NULL, NULL, 2000);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
err = net_mdns_autodiscover_and_store("_http", "_tcp", 8086,
|
|
||||||
NULL, NULL, 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err == ESP_OK) {
|
|
||||||
sys_status_set_mdns_ok(true);
|
|
||||||
ESP_LOGI(TAG, "mDNS: Service gefunden und gespeichert. Beende Re-Try-Task.");
|
|
||||||
vTaskDelete(NULL); // fertig, keine weiteren Versuche
|
|
||||||
} else {
|
|
||||||
sys_status_set_mdns_ok(false);
|
|
||||||
ESP_LOGW(TAG, "mDNS: nichts gefunden – neuer Versuch in 60 s");
|
|
||||||
vTaskDelay(kDelay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,24 +1,10 @@
|
|||||||
|
set(app_sources
|
||||||
|
"main.c"
|
||||||
|
"lv_fs_port.c"
|
||||||
|
)
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS ${app_sources}
|
||||||
"main.c"
|
INCLUDE_DIRS "."
|
||||||
"lv_fs_port.c"
|
REQUIRES dns_captive storage
|
||||||
"i2cdev.c"
|
)
|
||||||
"sensirion_common.c"
|
|
||||||
"sensirion_i2c.c"
|
|
||||||
"sensirion_i2c_hal.c"
|
|
||||||
"sen5x_i2c.c"
|
|
||||||
"sen5x_app.c"
|
|
||||||
"wifi_mgr.c"
|
|
||||||
"http_portal.c"
|
|
||||||
"storage.c"
|
|
||||||
"dns_captive.c"
|
|
||||||
"net_mdns.c"
|
|
||||||
"net_influx.c"
|
|
||||||
"sys_status.c"
|
|
||||||
INCLUDE_DIRS
|
|
||||||
"."
|
|
||||||
REQUIRES
|
|
||||||
driver
|
|
||||||
freertos
|
|
||||||
log
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/event_groups.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_http_server.h"
|
|
||||||
|
|
||||||
// Startet den HTTP-Captive-Portal Server.
|
|
||||||
// - wifi_events: EventGroup, die vom WiFi-Manager gepflegt wird
|
|
||||||
// - bit_gotip: Bitmaske für "STA hat IP"
|
|
||||||
// - bit_fail: Bitmaske für "STA Verbindung fehlgeschlagen"
|
|
||||||
// - ap_ssid: SSID des SoftAP (für Anzeige im HTML)
|
|
||||||
esp_err_t portal_http_start(EventGroupHandle_t wifi_events,
|
|
||||||
EventBits_t bit_gotip,
|
|
||||||
EventBits_t bit_fail,
|
|
||||||
const char* ap_ssid);
|
|
||||||
|
|
||||||
// Stoppt den HTTP-Server (optional)
|
|
||||||
void portal_http_stop(void);
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
#include "wifi_mgr.h"
|
|
||||||
#include "sen5x_app.h"
|
#include "sen5x_app.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
|
||||||
@@ -42,7 +41,36 @@
|
|||||||
#include "images.h"
|
#include "images.h"
|
||||||
#include "screens.h" // <-- Zugriff auf objects.* und tick_screen()
|
#include "screens.h" // <-- Zugriff auf objects.* und tick_screen()
|
||||||
|
|
||||||
// Entfernt: extern lv_obj_t *ui_wifi/influx/mdns;
|
#include "wifi_mgr.h"
|
||||||
|
#include "dns_captive.h"
|
||||||
|
#include "http_portal.h"
|
||||||
|
|
||||||
|
#include "net_mdns.h"
|
||||||
|
|
||||||
|
#include "esp_timer.h"
|
||||||
|
|
||||||
|
// --- Callback-Implementierungen für das Portal ---
|
||||||
|
|
||||||
|
static bool app_load_sta_creds(char **ssid, char **pass)
|
||||||
|
{
|
||||||
|
// Wenn du das Portal später mal /scan oder Default-SSID aus NVS ziehen lassen willst
|
||||||
|
return storage_load_wifi_creds(ssid, pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void app_save_sta_creds_and_reconnect(const char *ssid, const char *pass)
|
||||||
|
{
|
||||||
|
wifi_mgr_save_sta_creds_and_reconnect(ssid, pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void app_save_device_info(
|
||||||
|
const char *devicename,
|
||||||
|
const char *token,
|
||||||
|
const char *bucket,
|
||||||
|
const char *org)
|
||||||
|
{
|
||||||
|
storage_save_device_name(devicename);
|
||||||
|
storage_save_influx_softap(org, bucket, token);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Status-Icons updaten: nutzt die in screens.c erzeugten Objekte ----------
|
// ---------- Status-Icons updaten: nutzt die in screens.c erzeugten Objekte ----------
|
||||||
static void ui_update_status_icons(void)
|
static void ui_update_status_icons(void)
|
||||||
@@ -126,6 +154,16 @@ static lv_indev_t *lvgl_touch_indev = NULL;
|
|||||||
/* --- Button Handle global halten, falls benötigt --- */
|
/* --- Button Handle global halten, falls benötigt --- */
|
||||||
static button_handle_t g_btn = NULL;
|
static button_handle_t g_btn = NULL;
|
||||||
|
|
||||||
|
static void app_update_mdns_status_from_nvs(void)
|
||||||
|
{
|
||||||
|
char *url = NULL;
|
||||||
|
bool ok = storage_load_service_url(&url);
|
||||||
|
|
||||||
|
sys_status_set_mdns_ok(ok && url && url[0]); // nur mDNS
|
||||||
|
|
||||||
|
if (url) free(url);
|
||||||
|
}
|
||||||
|
|
||||||
/* Vorwärtsdeklarationen */
|
/* Vorwärtsdeklarationen */
|
||||||
void lv_fs_fatfs_init(void);
|
void lv_fs_fatfs_init(void);
|
||||||
static esp_err_t app_lvgl_init(void);
|
static esp_err_t app_lvgl_init(void);
|
||||||
@@ -199,6 +237,7 @@ static esp_err_t app_lvgl_init(void)
|
|||||||
|
|
||||||
static void ui_tick_cb(lv_timer_t *t) {
|
static void ui_tick_cb(lv_timer_t *t) {
|
||||||
(void)t;
|
(void)t;
|
||||||
|
app_update_mdns_status_from_nvs();
|
||||||
if (lvgl_port_lock(0)) {
|
if (lvgl_port_lock(0)) {
|
||||||
ui_update_status_icons();
|
ui_update_status_icons();
|
||||||
tick_screen(0);
|
tick_screen(0);
|
||||||
@@ -308,14 +347,11 @@ static void button_init(void)
|
|||||||
// Beim Loslassen nach langem Drücken -> wirklich resetten
|
// Beim Loslassen nach langem Drücken -> wirklich resetten
|
||||||
iot_button_register_cb(g_btn, BUTTON_LONG_PRESS_UP, NULL, reset_button_cb, NULL);
|
iot_button_register_cb(g_btn, BUTTON_LONG_PRESS_UP, NULL, reset_button_cb, NULL);
|
||||||
}
|
}
|
||||||
|
/* ==================== main ==================== */
|
||||||
/* ==================== app_main (unverändert, plus Button-Reset) ==================== */
|
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
esp_log_level_set("storage", ESP_LOG_NONE);
|
esp_log_level_set("storage", ESP_LOG_NONE);
|
||||||
*/
|
|
||||||
|
|
||||||
esp_log_level_set("*", ESP_LOG_NONE);
|
esp_log_level_set("*", ESP_LOG_NONE);
|
||||||
|
|
||||||
@@ -323,8 +359,8 @@ void app_main(void)
|
|||||||
sys_status_set_wifi_ok(false);
|
sys_status_set_wifi_ok(false);
|
||||||
sys_status_set_influx_ok(false);
|
sys_status_set_influx_ok(false);
|
||||||
sys_status_set_mdns_ok(false);
|
sys_status_set_mdns_ok(false);
|
||||||
|
*/
|
||||||
// 0) NVS zuerst
|
// NVS zuerst
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
@@ -332,21 +368,19 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
// --- Storage/WiFi wie gehabt ---
|
// --- Storage
|
||||||
ESP_ERROR_CHECK(storage_init());
|
ESP_ERROR_CHECK(storage_init());
|
||||||
storage_debug_dump();
|
storage_debug_dump();
|
||||||
|
// WiFi Manager initialisieren
|
||||||
wifi_mgr_init();
|
wifi_mgr_init();
|
||||||
wifi_mgr_start();
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2cdev_init());
|
ESP_ERROR_CHECK(i2cdev_init());
|
||||||
|
|
||||||
// 1) I2C-Bus initialisieren (bsp_i2c.h)
|
|
||||||
i2c_master_bus_handle_t i2c_bus_handle = bsp_i2c_init();
|
i2c_master_bus_handle_t i2c_bus_handle = bsp_i2c_init();
|
||||||
|
|
||||||
// 2) Diesen Bus von i2cdev "adoptieren", damit SEN5x denselben Bus nutzt
|
ESP_ERROR_CHECK(i2cdev_adopt_bus(I2C_PORT_NUM, i2c_bus_handle,
|
||||||
ESP_ERROR_CHECK(i2cdev_adopt_bus(0, i2c_bus_handle, 18, 19)); // Port 0, SDA=18, SCL=19
|
EXAMPLE_PIN_I2C_SDA, EXAMPLE_PIN_I2C_SCL));
|
||||||
|
// Restliche Peripherie
|
||||||
// 3) Restliche Peripherie
|
|
||||||
bsp_spi_init();
|
bsp_spi_init();
|
||||||
bsp_battery_init();
|
bsp_battery_init();
|
||||||
// bsp_qmi8658_init(i2c_bus_handle);
|
// bsp_qmi8658_init(i2c_bus_handle);
|
||||||
@@ -370,19 +404,66 @@ void app_main(void)
|
|||||||
lv_timer_t *ui_timer = lv_timer_create(ui_tick_cb, 1000, NULL);
|
lv_timer_t *ui_timer = lv_timer_create(ui_tick_cb, 1000, NULL);
|
||||||
(void)ui_timer;
|
(void)ui_timer;
|
||||||
|
|
||||||
// 4) SEN5x
|
// WiFi AP+STA starten
|
||||||
|
wifi_mgr_start();
|
||||||
|
|
||||||
|
// --- mDNS: Autostart (startet bei STA_GOT_IP automatisch) ---
|
||||||
|
ESP_ERROR_CHECK(net_mdns_autostart_init(NULL, NULL));
|
||||||
|
|
||||||
|
// --- mDNS: Service-Discovery mit Retry (ersetzt mdns_discover_task in wifi_mgr) ---
|
||||||
|
net_mdns_discover_cfg_t mdns_cfg = {
|
||||||
|
.service = "_influxdb2",
|
||||||
|
.proto = "_tcp",
|
||||||
|
.enforce_port = 8086,
|
||||||
|
|
||||||
|
.fallback_service = "_http",
|
||||||
|
.fallback_proto = "_tcp",
|
||||||
|
.fallback_port = 8086,
|
||||||
|
|
||||||
|
.txt_key = NULL,
|
||||||
|
.txt_value = NULL,
|
||||||
|
|
||||||
|
.query_timeout_ms = 2000,
|
||||||
|
.retry_interval_ms = 60000,
|
||||||
|
.max_results = 5,
|
||||||
|
|
||||||
|
.instance_prefix = NULL,
|
||||||
|
.require_instance_prefix = false
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(net_mdns_autodiscover_start(&mdns_cfg));
|
||||||
|
|
||||||
|
// AP-Netif an DNS weitergeben
|
||||||
|
dns_captive_set_ap_netif(wifi_mgr_get_ap_netif());
|
||||||
|
// Captive-DNS starten
|
||||||
|
ESP_ERROR_CHECK(dns_captive_start());
|
||||||
|
|
||||||
|
portal_http_callbacks_t cb = {
|
||||||
|
.load_sta_creds = app_load_sta_creds,
|
||||||
|
.save_sta_creds_and_reconnect= app_save_sta_creds_and_reconnect,
|
||||||
|
.save_device_info = app_save_device_info
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(portal_http_start(
|
||||||
|
wifi_mgr_get_event_group(),
|
||||||
|
wifi_mgr_evt_sta_got_ip(),
|
||||||
|
wifi_mgr_evt_sta_fail(),
|
||||||
|
"nanoPSX",
|
||||||
|
&cb
|
||||||
|
));
|
||||||
|
|
||||||
|
// SEN5x
|
||||||
const sen5x_i2c_cfg_t cfg = {
|
const sen5x_i2c_cfg_t cfg = {
|
||||||
.addr = 0x69,
|
.addr = 0x69,
|
||||||
.port = 0,
|
.port = I2C_PORT_NUM,
|
||||||
.sda = 18,
|
.sda = EXAMPLE_PIN_I2C_SDA,
|
||||||
.scl = 19,
|
.scl = EXAMPLE_PIN_I2C_SCL,
|
||||||
.sda_pullup = true,
|
.sda_pullup = true,
|
||||||
.scl_pullup = true,
|
.scl_pullup = true,
|
||||||
.freq = 400000
|
.freq = 400000
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(sen5x_app_init(&cfg));
|
ESP_ERROR_CHECK(sen5x_app_init(&cfg));
|
||||||
|
|
||||||
// 5) Task starten
|
// Task starten
|
||||||
xTaskCreate(sen5x_app_task, "sen5x_task", 4096, NULL, 5, NULL);
|
xTaskCreate(sen5x_app_task, "sen5x_task", 4096, NULL, 5, NULL);
|
||||||
|
|
||||||
for (;;) vTaskDelay(pdMS_TO_TICKS(1000));
|
for (;;) vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
|||||||
@@ -1,318 +0,0 @@
|
|||||||
// File: src/net_influx.c
|
|
||||||
#include "storage.h"
|
|
||||||
#include "net_influx.h"
|
|
||||||
#include "esp_http_client.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "sys_status.h"
|
|
||||||
|
|
||||||
static const char* TAG = "net_influx";
|
|
||||||
|
|
||||||
/* ---------------- State (mit internen Kopien!) ---------------- */
|
|
||||||
typedef struct {
|
|
||||||
char url_base[128];
|
|
||||||
char org[64];
|
|
||||||
char bucket[64];
|
|
||||||
char token[512]; // lang genug für Influx Token
|
|
||||||
bool use_tls;
|
|
||||||
const char* ca_cert_pem;
|
|
||||||
int http_timeout_ms;
|
|
||||||
} net_influx_state_t;
|
|
||||||
|
|
||||||
static net_influx_state_t s = {0};
|
|
||||||
|
|
||||||
/* ---------------- Utils ---------------- */
|
|
||||||
static void trim_inplace(char* p) {
|
|
||||||
if (!p) return;
|
|
||||||
size_t len = strlen(p);
|
|
||||||
size_t a = 0, b = len;
|
|
||||||
while (a < b && (isspace((unsigned char)p[a]) || p[a] == '\"')) a++;
|
|
||||||
while (b > a && (isspace((unsigned char)p[b-1]) || p[b-1] == '\"' || p[b-1] == '/')) b--;
|
|
||||||
if (a || b != len) {
|
|
||||||
memmove(p, p + a, b - a);
|
|
||||||
p[b - a] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void safe_copy(char* dst, size_t dst_sz, const char* src) {
|
|
||||||
if (!dst || dst_sz == 0) return;
|
|
||||||
if (!src) { dst[0] = 0; return; }
|
|
||||||
strncpy(dst, src, dst_sz - 1);
|
|
||||||
dst[dst_sz - 1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool tls; // http=false, https=true
|
|
||||||
char host[64];
|
|
||||||
int port; // -1 = nicht angegeben
|
|
||||||
} base_parts_t;
|
|
||||||
|
|
||||||
// erwartet: "http://host:port" oder "host:port" oder "host"
|
|
||||||
static bool parse_base_url(const char* in, base_parts_t* out) {
|
|
||||||
if (!in || !*in || !out) return false;
|
|
||||||
|
|
||||||
char buf[128];
|
|
||||||
safe_copy(buf, sizeof(buf), in);
|
|
||||||
trim_inplace(buf);
|
|
||||||
|
|
||||||
const char* p = buf;
|
|
||||||
out->tls = false;
|
|
||||||
out->port = -1;
|
|
||||||
memset(out->host, 0, sizeof(out->host));
|
|
||||||
|
|
||||||
if (strncasecmp(p, "http://", 7) == 0) { p += 7; out->tls = false; }
|
|
||||||
else if (strncasecmp(p, "https://", 8) == 0) { p += 8; out->tls = true; }
|
|
||||||
|
|
||||||
const char* colon = strchr(p, ':');
|
|
||||||
if (colon) {
|
|
||||||
size_t host_len = (size_t)(colon - p);
|
|
||||||
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
|
|
||||||
memcpy(out->host, p, host_len);
|
|
||||||
out->host[host_len] = 0;
|
|
||||||
|
|
||||||
const char* port_str = colon + 1;
|
|
||||||
if (!*port_str) return false;
|
|
||||||
int port = 0;
|
|
||||||
while (*port_str && isdigit((unsigned char)*port_str)) {
|
|
||||||
port = port * 10 + (*port_str - '0');
|
|
||||||
port_str++;
|
|
||||||
}
|
|
||||||
if (*port_str != 0) return false; // kein weiterer Kram erlaubt
|
|
||||||
out->port = port;
|
|
||||||
} else {
|
|
||||||
size_t host_len = strlen(p);
|
|
||||||
if (host_len == 0 || host_len >= sizeof(out->host)) return false;
|
|
||||||
memcpy(out->host, p, host_len);
|
|
||||||
out->host[host_len] = 0;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mask_token(const char* token, char* out, size_t out_len) {
|
|
||||||
if (!token || !out || out_len < 8) return;
|
|
||||||
size_t n = strlen(token);
|
|
||||||
if (n <= 8) {
|
|
||||||
snprintf(out, out_len, "****");
|
|
||||||
} else {
|
|
||||||
size_t keep = 4;
|
|
||||||
snprintf(out, out_len, "%.*s****%.*s",
|
|
||||||
(int)keep, token,
|
|
||||||
(int)keep, token + n - keep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- HTTP Event Handler (IDF-kompatibel) ---------------- */
|
|
||||||
static esp_err_t http_evt(esp_http_client_event_t* evt) {
|
|
||||||
switch (evt->event_id) {
|
|
||||||
case HTTP_EVENT_ERROR: ESP_LOGE(TAG, "HTTP_EVENT_ERROR"); break;
|
|
||||||
case HTTP_EVENT_ON_CONNECTED: ESP_LOGI(TAG, "HTTP_EVENT_ON_CONNECTED"); break;
|
|
||||||
case HTTP_EVENT_HEADER_SENT: ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT"); break;
|
|
||||||
case HTTP_EVENT_ON_HEADER:
|
|
||||||
ESP_LOGD(TAG, "HDR: %s: %s",
|
|
||||||
evt->header_key ? evt->header_key : "(null)",
|
|
||||||
evt->header_value ? evt->header_value : "(null)");
|
|
||||||
break;
|
|
||||||
case HTTP_EVENT_ON_DATA: ESP_LOGV(TAG, "DATA chunk len=%d", evt->data_len); break;
|
|
||||||
case HTTP_EVENT_ON_FINISH: ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH"); break;
|
|
||||||
case HTTP_EVENT_DISCONNECTED: ESP_LOGW(TAG, "HTTP_EVENT_DISCONNECTED"); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- Public API ---------------- */
|
|
||||||
esp_err_t net_influx_init(const net_influx_cfg_t* cfg) {
|
|
||||||
if (!cfg || !cfg->url_base || !cfg->org || !cfg->bucket || !cfg->token) {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
safe_copy(s.url_base, sizeof(s.url_base), cfg->url_base);
|
|
||||||
safe_copy(s.org, sizeof(s.org), cfg->org);
|
|
||||||
safe_copy(s.bucket, sizeof(s.bucket), cfg->bucket);
|
|
||||||
safe_copy(s.token, sizeof(s.token), cfg->token);
|
|
||||||
trim_inplace(s.url_base);
|
|
||||||
|
|
||||||
s.use_tls = cfg->use_tls;
|
|
||||||
s.ca_cert_pem = cfg->ca_cert_pem;
|
|
||||||
s.http_timeout_ms = (cfg->http_timeout_ms > 0) ? cfg->http_timeout_ms : 3000;
|
|
||||||
|
|
||||||
char tok[32] = {0};
|
|
||||||
mask_token(s.token, tok, sizeof(tok));
|
|
||||||
ESP_LOGI(TAG, "init: base=\"%s\", org=\"%s\", bucket=\"%s\", tls=%d, timeout=%dms, token=%s",
|
|
||||||
s.url_base, s.org, s.bucket, (int)s.use_tls, s.http_timeout_ms, tok);
|
|
||||||
sys_status_set_influx_ok(false);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t net_influx_write_fields(const char* measurement,
|
|
||||||
const char* tags,
|
|
||||||
uint64_t ts_ms,
|
|
||||||
const char* fields_fmt,
|
|
||||||
...)
|
|
||||||
{
|
|
||||||
// --- Neu: pessimistisch starten ---
|
|
||||||
bool ok = false;
|
|
||||||
|
|
||||||
if (!measurement || !fields_fmt) {
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
if (s.url_base[0] == 0 || s.org[0] == 0 || s.bucket[0] == 0 || s.token[0] == 0) {
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1) Fields formatieren
|
|
||||||
char fields[256];
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fields_fmt);
|
|
||||||
vsnprintf(fields, sizeof(fields), fields_fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
// 2) Line Protocol
|
|
||||||
char line[400];
|
|
||||||
int off = 0;
|
|
||||||
off += snprintf(line + off, sizeof(line) - off, "%s", measurement);
|
|
||||||
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; } // <—
|
|
||||||
if (tags && *tags) {
|
|
||||||
off += snprintf(line + off, sizeof(line) - off, ",%s", tags);
|
|
||||||
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; } // <—
|
|
||||||
}
|
|
||||||
off += snprintf(line + off, sizeof(line) - off, " %s", fields);
|
|
||||||
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; } // <—
|
|
||||||
if (ts_ms != 0) {
|
|
||||||
off += snprintf(line + off, sizeof(line) - off, " %llu", (unsigned long long)ts_ms);
|
|
||||||
if (off < 0 || off >= (int)sizeof(line)) { sys_status_set_influx_ok(false); return ESP_FAIL; } // <—
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) Base parse → host/port/tls
|
|
||||||
base_parts_t bp;
|
|
||||||
if (!parse_base_url(s.url_base, &bp)) {
|
|
||||||
ESP_LOGE(TAG, "Base-URL ungueltig: \"%s\"", s.url_base);
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
if (s.use_tls) bp.tls = true;
|
|
||||||
int port = (bp.port > 0) ? bp.port : (bp.tls ? 443 : 8086);
|
|
||||||
|
|
||||||
// 4) Pfad (Tipp: URL-encoding wenn org/bucket Sonderzeichen haben könnten)
|
|
||||||
char path[192];
|
|
||||||
snprintf(path, sizeof(path), "/api/v2/write?org=%s&bucket=%s&precision=ms", s.org, s.bucket);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "HTTP cfg: host=%s, port=%d, path=%s, tls=%d", bp.host, port, path, (int)bp.tls);
|
|
||||||
ESP_LOGD(TAG, "Line: %s", line);
|
|
||||||
|
|
||||||
// 5) HTTP-Client
|
|
||||||
esp_http_client_config_t cfg = {
|
|
||||||
.host = bp.host,
|
|
||||||
.port = port,
|
|
||||||
.path = path,
|
|
||||||
.timeout_ms = s.http_timeout_ms,
|
|
||||||
.cert_pem = bp.tls ? s.ca_cert_pem : NULL,
|
|
||||||
.method = HTTP_METHOD_POST,
|
|
||||||
.event_handler = http_evt,
|
|
||||||
.transport_type = bp.tls ? HTTP_TRANSPORT_OVER_SSL : HTTP_TRANSPORT_OVER_TCP,
|
|
||||||
// Optional: stabiler auf schlechten Links
|
|
||||||
.disable_auto_redirect = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
esp_http_client_handle_t h = esp_http_client_init(&cfg);
|
|
||||||
if (!h) {
|
|
||||||
ESP_LOGE(TAG, "http_client_init: no mem");
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Header
|
|
||||||
size_t auth_len = strlen(s.token) + 7; // "Token " + '\0'
|
|
||||||
char* auth = (char*)malloc(auth_len);
|
|
||||||
if (!auth) {
|
|
||||||
ESP_LOGE(TAG, "malloc auth header: no mem");
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
snprintf(auth, auth_len, "Token %s", s.token);
|
|
||||||
esp_http_client_set_header(h, "Authorization", auth);
|
|
||||||
free(auth);
|
|
||||||
|
|
||||||
esp_http_client_set_header(h, "Content-Type", "text/plain; charset=utf-8");
|
|
||||||
// Optional hilfreich:
|
|
||||||
// esp_http_client_set_header(h, "Accept", "application/json");
|
|
||||||
// esp_http_client_set_header(h, "Connection", "close");
|
|
||||||
|
|
||||||
// Body
|
|
||||||
esp_err_t err = esp_http_client_set_post_field(h, line, (int)strlen(line));
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "set_post_field: %s", esp_err_to_name(err));
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
sys_status_set_influx_ok(false); // <—
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6) Request
|
|
||||||
err = esp_http_client_perform(h);
|
|
||||||
|
|
||||||
int status = -1;
|
|
||||||
if (err == ESP_OK) {
|
|
||||||
status = esp_http_client_get_status_code(h);
|
|
||||||
int64_t cl = esp_http_client_get_content_length(h);
|
|
||||||
ESP_LOGI(TAG, "HTTP status=%d, content_length=%lld", status, (long long)cl);
|
|
||||||
|
|
||||||
if (status != 204) {
|
|
||||||
char resp[256] = {0};
|
|
||||||
int n = esp_http_client_read_response(h, resp, sizeof(resp)-1);
|
|
||||||
if (n > 0) ESP_LOGW(TAG, "Resp(%d): %.*s", status, n, resp);
|
|
||||||
else ESP_LOGW(TAG, "Resp(%d): <kein Body>", status);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "perform: %s", esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_http_client_cleanup(h);
|
|
||||||
|
|
||||||
// --- Wichtig: Flag NACH allem zentral setzen ---
|
|
||||||
ok = (err == ESP_OK && status == 204);
|
|
||||||
sys_status_set_influx_ok(ok);
|
|
||||||
return ok ? ESP_OK : ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Aus NVS: URL (service_url), org/bucket/token → net_influx_init()
|
|
||||||
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms)
|
|
||||||
{
|
|
||||||
char *url = NULL, *org = NULL, *bucket = NULL, *token = NULL;
|
|
||||||
|
|
||||||
if (!storage_load_service_url(&url)) {
|
|
||||||
ESP_LOGW(TAG, "keine Service-URL in NVS gefunden (mDNS noch nicht fertig?)");
|
|
||||||
// Du kannst hier optional einen Default setzen oder ESP_ERR_NOT_FOUND zurückgeben
|
|
||||||
return ESP_ERR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
if (!storage_get_effective_influx(&org, &bucket, &token)) {
|
|
||||||
ESP_LOGE(TAG, "Influx-Konfiguration aus NVS nicht lesbar");
|
|
||||||
free(url);
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
net_influx_cfg_t cfg = {
|
|
||||||
.url_base = url, // z.B. "http://192.168.1.10:8086"
|
|
||||||
.org = org,
|
|
||||||
.bucket = bucket,
|
|
||||||
.token = token,
|
|
||||||
.use_tls = false, // URL-Parser erkennt https automatisch; true erzwingt TLS
|
|
||||||
.ca_cert_pem = ca_cert_pem_opt,
|
|
||||||
.http_timeout_ms = (timeout_ms > 0) ? timeout_ms : 3000
|
|
||||||
};
|
|
||||||
|
|
||||||
esp_err_t err = net_influx_init(&cfg);
|
|
||||||
|
|
||||||
free(url);
|
|
||||||
free(org);
|
|
||||||
free(bucket);
|
|
||||||
free(token);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
// File: include/net_influx.h
|
|
||||||
#pragma once
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "esp_err.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* url_base; // "http://host:8086" oder "https://host"
|
|
||||||
const char* org;
|
|
||||||
const char* bucket;
|
|
||||||
const char* token;
|
|
||||||
bool use_tls; // optional; wenn true => TLS erzwingen
|
|
||||||
const char* ca_cert_pem; // optional, bei https (kann NULL sein wenn Test)
|
|
||||||
int http_timeout_ms; // z.B. 3000
|
|
||||||
} net_influx_cfg_t;
|
|
||||||
|
|
||||||
esp_err_t net_influx_init(const net_influx_cfg_t* cfg);
|
|
||||||
|
|
||||||
// Convenience: lädt URL/org/bucket/token direkt aus NVS (storage.c)
|
|
||||||
esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms);
|
|
||||||
|
|
||||||
// generisches Write (Line Protocol Felderformatierung via printf)
|
|
||||||
esp_err_t net_influx_write_fields(const char* measurement,
|
|
||||||
const char* tags, // "k=v,k2=v2" oder NULL
|
|
||||||
uint64_t ts_ms, // 0 = Serverzeit
|
|
||||||
const char* fields_fmt,
|
|
||||||
...);
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_event.h"
|
|
||||||
#include "esp_netif.h"
|
|
||||||
#include "esp_wifi.h" // <— wichtig für WIFI_EVENT
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "mdns.h"
|
|
||||||
#include "net_mdns.h"
|
|
||||||
#include "storage.h"
|
|
||||||
|
|
||||||
static const char* TAG = "net_mdns";
|
|
||||||
static char g_hostname[33] = {0};
|
|
||||||
static char g_instance[33] = {0};
|
|
||||||
static volatile bool g_mdns_running = false;
|
|
||||||
|
|
||||||
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
|
|
||||||
int enforce_port,
|
|
||||||
const char *txt_key, const char *txt_value,
|
|
||||||
uint32_t timeout_ms)
|
|
||||||
{
|
|
||||||
char url[96] = {0};
|
|
||||||
bool ok = net_mdns_find_service_url(service, proto, enforce_port,
|
|
||||||
txt_key, txt_value, timeout_ms, 5,
|
|
||||||
url, sizeof(url));
|
|
||||||
if (!ok) {
|
|
||||||
ESP_LOGW(TAG, "Auto-Discover: kein Treffer für %s.%s", service, proto);
|
|
||||||
return ESP_ERR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t err = storage_save_service_url(url);
|
|
||||||
if (err == ESP_OK) {
|
|
||||||
ESP_LOGI(TAG, "Auto-Discover: URL '%s' in NVS gespeichert.", url);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mdns_start_if_needed(void) {
|
|
||||||
if (g_mdns_running) return;
|
|
||||||
esp_err_t err = mdns_init();
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "mdns_init failed: %s", esp_err_to_name(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (g_hostname[0]) mdns_hostname_set(g_hostname);
|
|
||||||
if (g_instance[0]) mdns_instance_name_set(g_instance);
|
|
||||||
g_mdns_running = true;
|
|
||||||
ESP_LOGI(TAG, "mDNS started (host=%s, inst=%s)", g_hostname, g_instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mdns_stop_if_running(void) {
|
|
||||||
if (!g_mdns_running) return;
|
|
||||||
mdns_free();
|
|
||||||
g_mdns_running = false;
|
|
||||||
ESP_LOGI(TAG, "mDNS stopped");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_ip_event(void* arg, esp_event_base_t base, int32_t id, void* data) {
|
|
||||||
if (base == IP_EVENT && id == IP_EVENT_STA_GOT_IP) {
|
|
||||||
mdns_start_if_needed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_wifi_event(void* arg, esp_event_base_t base, int32_t id, void* data) {
|
|
||||||
if (base == WIFI_EVENT && id == WIFI_EVENT_STA_DISCONNECTED) {
|
|
||||||
mdns_stop_if_running();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t net_mdns_autostart_init(const char* hostname, const char* instance_name) {
|
|
||||||
if (hostname) {
|
|
||||||
strncpy(g_hostname, hostname, sizeof(g_hostname)-1);
|
|
||||||
g_hostname[sizeof(g_hostname)-1] = '\0';
|
|
||||||
}
|
|
||||||
if (instance_name) {
|
|
||||||
strncpy(g_instance, instance_name, sizeof(g_instance)-1);
|
|
||||||
g_instance[sizeof(g_instance)-1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, on_ip_event, NULL, NULL));
|
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, on_wifi_event, NULL, NULL));
|
|
||||||
|
|
||||||
// Falls IP schon vorhanden:
|
|
||||||
esp_netif_t* sta = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
|
||||||
if (sta) {
|
|
||||||
esp_netif_ip_info_t ip;
|
|
||||||
if (esp_netif_get_ip_info(sta, &ip) == ESP_OK && ip.ip.addr != 0) {
|
|
||||||
mdns_start_if_needed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool net_mdns_is_running(void) {
|
|
||||||
return g_mdns_running;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool net_mdns_wait_started(uint32_t timeout_ms) {
|
|
||||||
uint32_t waited = 0;
|
|
||||||
const uint32_t step = 50;
|
|
||||||
while (!g_mdns_running && waited < timeout_ms) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(step));
|
|
||||||
waited += step;
|
|
||||||
}
|
|
||||||
return g_mdns_running;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t net_mdns_add_service(const char* service, const char* proto,
|
|
||||||
uint16_t port, mdns_txt_item_t* txt, size_t txt_count) {
|
|
||||||
if (!g_mdns_running) {
|
|
||||||
mdns_start_if_needed();
|
|
||||||
if (!g_mdns_running) return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
esp_err_t err = mdns_service_add(NULL, service, proto, port, txt, txt_count);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "mdns_service_add %s.%s:%u failed: %s", service, proto, port, esp_err_to_name(err));
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "mDNS service announced: %s.%s:%u", service, proto, port);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool net_mdns_find_service_url(const char* service, const char* proto,
|
|
||||||
int enforce_port, const char* txt_key, const char* txt_value,
|
|
||||||
uint32_t timeout_ms, int max_results,
|
|
||||||
char* url_out, size_t url_out_size) {
|
|
||||||
if (!service || !proto || !url_out || url_out_size < 16) return false;
|
|
||||||
if (!g_mdns_running) {
|
|
||||||
ESP_LOGW(TAG, "mDNS not running yet; waiting...");
|
|
||||||
if (!net_mdns_wait_started(3000)) {
|
|
||||||
ESP_LOGW(TAG, "mDNS still not running; abort query");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mdns_result_t* results = NULL;
|
|
||||||
esp_err_t err = mdns_query_ptr(service, proto, timeout_ms, max_results, &results);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "mdns_query_ptr error: %s", esp_err_to_name(err));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!results) {
|
|
||||||
ESP_LOGI(TAG, "mDNS query OK but no results for %s.%s", service, proto);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
for (mdns_result_t* r = results; r && !found; r = r->next) {
|
|
||||||
bool txt_ok = true;
|
|
||||||
if (txt_key && txt_value) {
|
|
||||||
txt_ok = false;
|
|
||||||
for (int i = 0; i < r->txt_count; ++i) {
|
|
||||||
if (r->txt[i].key && r->txt[i].value &&
|
|
||||||
strcmp(r->txt[i].key, txt_key) == 0 &&
|
|
||||||
strcmp(r->txt[i].value, txt_value) == 0) {
|
|
||||||
txt_ok = true; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!txt_ok) continue;
|
|
||||||
|
|
||||||
if (r->instance_name && strncmp(r->instance_name, "influxdb2-", 9) != 0) {
|
|
||||||
continue; // falsche Instanz, weitersuchen
|
|
||||||
}
|
|
||||||
|
|
||||||
for (mdns_ip_addr_t* a = r->addr; a && !found; a = a->next) {
|
|
||||||
if (a->addr.type != ESP_IPADDR_TYPE_V4) continue;
|
|
||||||
uint16_t port = r->port ? r->port : 80;
|
|
||||||
if (enforce_port > 0 && port != (uint16_t)enforce_port) port = (uint16_t)enforce_port;
|
|
||||||
snprintf(url_out, url_out_size, "http://" IPSTR ":%u", IP2STR(&a->addr.u_addr.ip4), (unsigned)port);
|
|
||||||
ESP_LOGI(TAG, "mDNS URL: %s", url_out);
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mdns_query_results_free(results);
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
void net_mdns_stop(void) { mdns_stop_if_running(); }
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// File: include/net_mdns.h
|
|
||||||
#pragma once
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "mdns.h"
|
|
||||||
|
|
||||||
esp_err_t net_mdns_autostart_init(const char* hostname, const char* instance_name);
|
|
||||||
bool net_mdns_is_running(void);
|
|
||||||
bool net_mdns_wait_started(uint32_t timeout_ms);
|
|
||||||
esp_err_t net_mdns_add_service(const char* service, const char* proto,
|
|
||||||
uint16_t port, mdns_txt_item_t* txt, size_t txt_count);
|
|
||||||
|
|
||||||
bool net_mdns_find_service_url(const char* service, const char* proto,
|
|
||||||
int enforce_port, const char* txt_key, const char* txt_value,
|
|
||||||
uint32_t timeout_ms, int max_results,
|
|
||||||
char* url_out, size_t url_out_size);
|
|
||||||
|
|
||||||
void net_mdns_stop(void);
|
|
||||||
|
|
||||||
// --- NEU: Auto-Discover + NVS persistieren ---
|
|
||||||
esp_err_t net_mdns_autodiscover_and_store(const char *service, const char *proto,
|
|
||||||
int enforce_port,
|
|
||||||
const char *txt_key, const char *txt_value,
|
|
||||||
uint32_t timeout_ms);
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
// File: sensirion_i2c_hal.c
|
|
||||||
#include "sensirion_i2c_hal.h"
|
|
||||||
#include "sensirion_common.h"
|
|
||||||
#include "sensirion_config.h"
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
#include <freertos/FreeRTOS.h>
|
|
||||||
#include <freertos/task.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <inttypes.h> // für PRIu32
|
|
||||||
|
|
||||||
#include "sensirion_i2c_esp32_config.h"
|
|
||||||
|
|
||||||
static const char* TAG = "sensirion_i2c_hal";
|
|
||||||
|
|
||||||
#define SLEEP_MS(x) \
|
|
||||||
vTaskDelay(((x) + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS)
|
|
||||||
|
|
||||||
// Lokaler I2C-Gerätekontext aus i2cdev
|
|
||||||
static i2c_dev_t dev = {0};
|
|
||||||
static struct esp32_i2c_config i2c_cfg = {0};
|
|
||||||
static esp_err_t i2c_ok = ESP_OK;
|
|
||||||
|
|
||||||
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx) {
|
|
||||||
// Multi-Bus-Support: Port umschalten (optional, für Single-Bus reicht das so)
|
|
||||||
dev.port = bus_idx;
|
|
||||||
i2c_cfg.port = bus_idx;
|
|
||||||
ESP_LOGI(TAG, "Selected I2C bus index/port: %u", (unsigned)bus_idx);
|
|
||||||
return NO_ERROR; // 0
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t sensirion_i2c_config_esp32(struct esp32_i2c_config* cfg) {
|
|
||||||
if (cfg != NULL) {
|
|
||||||
memcpy(&i2c_cfg, cfg, sizeof(*cfg));
|
|
||||||
return ESP_OK;
|
|
||||||
} else {
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t sensirion_i2c_esp32_ok(void) {
|
|
||||||
return i2c_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize all hard- and software components that are needed for the I2C
|
|
||||||
* communication.
|
|
||||||
*/
|
|
||||||
void sensirion_i2c_hal_init(void) {
|
|
||||||
memset(&dev, 0, sizeof(i2c_dev_t));
|
|
||||||
|
|
||||||
// Port & Pins/Frequenz aus der App-Konfiguration übernehmen
|
|
||||||
dev.port = i2c_cfg.port;
|
|
||||||
dev.cfg.sda_io_num = i2c_cfg.sda;
|
|
||||||
dev.cfg.scl_io_num = i2c_cfg.scl;
|
|
||||||
dev.cfg.sda_pullup_en = i2c_cfg.sda_pullup;
|
|
||||||
dev.cfg.scl_pullup_en = i2c_cfg.scl_pullup;
|
|
||||||
#if HELPER_TARGET_IS_ESP32
|
|
||||||
dev.cfg.master.clk_speed = i2c_cfg.freq; // Gerätespezifische Busgeschwindigkeit
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Mutex anlegen & Gerät registrieren (i2cdev kümmert sich um Bus-Setup on-demand)
|
|
||||||
esp_err_t err = i2c_dev_create_mutex(&dev);
|
|
||||||
if (err == ESP_OK) {
|
|
||||||
ESP_LOGI(TAG,
|
|
||||||
"Sensirion I2C HAL ready. Addr: 0x%02x Port: %d SDA: %d SCL: %d Freq: %" PRIu32 "Hz",
|
|
||||||
i2c_cfg.addr, i2c_cfg.port, i2c_cfg.sda, i2c_cfg.scl,
|
|
||||||
(uint32_t)i2c_cfg.freq);
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG,
|
|
||||||
"Sensirion I2C HAL init error! Addr: 0x%02x Port: %d SDA: %d SCL: %d (err=%s)",
|
|
||||||
i2c_cfg.addr, i2c_cfg.port, i2c_cfg.sda, i2c_cfg.scl,
|
|
||||||
esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
i2c_ok = err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Release all resources initialized by sensirion_i2c_hal_init().
|
|
||||||
*/
|
|
||||||
void sensirion_i2c_hal_free(void) {
|
|
||||||
// Gibt Mutex frei, deregistriert Device & entfernt ggf. Bus-Handle wenn letztes Gerät (siehe i2cdev.c)
|
|
||||||
esp_err_t err = i2c_dev_delete_mutex(&dev);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "i2c_dev_delete_mutex failed: %s", esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute one read transaction on the I2C bus, reading a given number of bytes.
|
|
||||||
* If the device does not acknowledge the read command, an error shall be
|
|
||||||
* returned.
|
|
||||||
*
|
|
||||||
* @param address 7-bit I2C address to read from
|
|
||||||
* @param data pointer to the buffer where the data is to be stored
|
|
||||||
* @param count number of bytes to read from I2C and store in the buffer
|
|
||||||
* @returns 0 on success, error code otherwise
|
|
||||||
*/
|
|
||||||
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
|
|
||||||
ESP_LOGD(TAG, "sensirion_i2c_hal_read: addr=0x%02x len=%u", address, (unsigned)count);
|
|
||||||
dev.addr = address;
|
|
||||||
|
|
||||||
I2C_DEV_TAKE_MUTEX(&dev);
|
|
||||||
esp_err_t err = i2c_dev_read(&dev, NULL, 0, data, count);
|
|
||||||
I2C_DEV_GIVE_MUTEX(&dev);
|
|
||||||
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "READ failed (addr=0x%02x, len=%u): %s", address, (unsigned)count, esp_err_to_name(err));
|
|
||||||
return (int8_t)err; // non-zero -> Fehler
|
|
||||||
}
|
|
||||||
// ESP_LOGV(TAG, "READ OK");
|
|
||||||
return (int8_t)NO_ERROR; // 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute one write transaction on the I2C bus, sending a given number of
|
|
||||||
* bytes.
|
|
||||||
*
|
|
||||||
* @param address 7-bit I2C address to write to
|
|
||||||
* @param data pointer to the buffer containing the data to write
|
|
||||||
* @param count number of bytes to send over I2C
|
|
||||||
* @returns 0 on success, error code otherwise
|
|
||||||
*/
|
|
||||||
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data,
|
|
||||||
uint16_t count) {
|
|
||||||
ESP_LOGD(TAG, "sensirion_i2c_hal_write: addr=0x%02x len=%u", address, (unsigned)count);
|
|
||||||
dev.addr = address;
|
|
||||||
|
|
||||||
I2C_DEV_TAKE_MUTEX(&dev);
|
|
||||||
esp_err_t err = i2c_dev_write(&dev, NULL, 0, data, count);
|
|
||||||
I2C_DEV_GIVE_MUTEX(&dev);
|
|
||||||
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGW(TAG, "WRITE failed (addr=0x%02x, len=%u): %s", address, (unsigned)count, esp_err_to_name(err));
|
|
||||||
return (int8_t)err; // non-zero -> Fehler
|
|
||||||
}
|
|
||||||
// ESP_LOGV(TAG, "WRITE OK");
|
|
||||||
return (int8_t)NO_ERROR; // 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sleep for a given number of microseconds. The function should delay the
|
|
||||||
* execution for at least the given time, but may also sleep longer.
|
|
||||||
*
|
|
||||||
* Despite the unit, a <10 millisecond precision is sufficient.
|
|
||||||
*
|
|
||||||
* @param useconds the sleep time in microseconds
|
|
||||||
*/
|
|
||||||
void sensirion_i2c_hal_sleep_usec(uint32_t useconds) {
|
|
||||||
ESP_LOGV(TAG, "sensirion_i2c_hal_sleep: %" PRIu32 " usec", useconds);
|
|
||||||
// Tick-basiert schlafen (µs->ms), Genauigkeit im Bereich <10 ms ist ausreichend
|
|
||||||
uint32_t ms = useconds / 1000U;
|
|
||||||
if (ms == 0 && useconds > 0) {
|
|
||||||
// Mindestens 1 Tick warten, wenn >0µs angefordert, um aktives Busy-Wait zu vermeiden
|
|
||||||
ms = 1;
|
|
||||||
}
|
|
||||||
SLEEP_MS(ms);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialisiert NVS, Netif, Eventloop, Wi-Fi, registriert Event-Handler und legt den AP-Auto-Off-Timer an.
|
|
||||||
void wifi_mgr_init(void);
|
|
||||||
|
|
||||||
// Startet AP+STA, HTTP-Server und DNS-Server, und stößt ggf. eine STA-Verbindung an.
|
|
||||||
void wifi_mgr_start(void);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
// File: src/http_portal.c
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/event_groups.h"
|
|
||||||
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_wifi.h"
|
|
||||||
#include "esp_http_server.h"
|
|
||||||
|
|
||||||
#include "http_portal.h"
|
|
||||||
#include "storage.h"
|
|
||||||
|
|
||||||
// Provided by WiFi Manager (defined in wifi_mgr.c)
|
|
||||||
bool wifi_mgr_load_sta_creds(char **out_ssid, char **out_pass);
|
|
||||||
void wifi_mgr_save_sta_creds_and_reconnect(const char* ssid, const char* pass);
|
|
||||||
|
|
||||||
// NEW: Save device properties (implemented in wifi_mgr.c)
|
|
||||||
void wifi_mgr_save_device_info(const char* devicename, const char* token, const char* bucket, const char* org);
|
|
||||||
|
|
||||||
static char* html_escape(const char* s) {
|
|
||||||
if (!s) return strdup("");
|
|
||||||
size_t len = 0;
|
|
||||||
for (const char* p = s; *p; ++p) {
|
|
||||||
switch(*p){ case '&': len+=5; break; case '<': case '>': len+=4; break; case '"': case '\'': len+=6; break; default: len+=1; }
|
|
||||||
}
|
|
||||||
char* out = (char*)malloc(len+1); if(!out) return NULL;
|
|
||||||
char* o = out;
|
|
||||||
for (const char* p = s; *p; ++p) {
|
|
||||||
switch(*p){
|
|
||||||
case '&': memcpy(o,"&",5); o+=5; break;
|
|
||||||
case '<': memcpy(o,"<",4); o+=4; break;
|
|
||||||
case '>': memcpy(o,">",4); o+=4; break;
|
|
||||||
case '"': memcpy(o,""",6);o+=6; break;
|
|
||||||
case '\'':memcpy(o,"'",5); o+=5; break;
|
|
||||||
default: *o++ = *p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*o = '\0';
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *TAG = "portal_http";
|
|
||||||
|
|
||||||
static httpd_handle_t s_http = NULL;
|
|
||||||
static EventGroupHandle_t s_wifi_events = NULL;
|
|
||||||
static EventBits_t s_BIT_GOTIP = 0;
|
|
||||||
static EventBits_t s_BIT_FAIL = 0;
|
|
||||||
static char s_ap_ssid[33] = {0};
|
|
||||||
|
|
||||||
// ---------- HTML (template with placeholders) ----------
|
|
||||||
static const char form_html_tpl[] =
|
|
||||||
"<!doctype html><html><head><meta charset='utf-8'/>"
|
|
||||||
"<meta name='viewport' content='width=device-width,initial-scale=1'/>"
|
|
||||||
"<title>Wi-Fi Setup</title>"
|
|
||||||
"<style>body{font-family:system-ui,Arial;margin:2rem;line-height:1.4}"
|
|
||||||
"label{display:block;margin-top:1rem}input,select{padding:.5rem;width:100%%;max-width:28rem}"
|
|
||||||
"button{margin-top:1rem;padding:.6rem 1rem;border:0;border-radius:.6rem;background:#0b6cff;color:#fff;}"
|
|
||||||
".card{max-width:32rem;padding:1rem 1.25rem;border:1px solid #e5e5e5;border-radius:1rem;box-shadow:0 2px 10px rgba(0,0,0,.04)}"
|
|
||||||
".row{display:flex;gap:.5rem;align-items:center;max-width:28rem}"
|
|
||||||
".muted{color:#666;font-size:.9em}</style>"
|
|
||||||
"</head><body><div class='card'>"
|
|
||||||
"<h1>Wi-Fi Configuration</h1>"
|
|
||||||
"<p>Connected to <b>%s</b>. Choose your Wi-Fi network or enter it manually:</p>"
|
|
||||||
"<div class='row'><select id='nets'></select><button id='refresh' type='button'>Refresh</button></div>"
|
|
||||||
"<form method='POST' action='/save'>"
|
|
||||||
"<label>SSID*<input id='ssid' name='ssid' required></label>"
|
|
||||||
"<label>Password*<input name='pass' type='password' required></label>"
|
|
||||||
"<label>Device Name*<input id='dev' name='dev' required value='%s' placeholder=''></label>"
|
|
||||||
"<label>Organization (optional)<input id='org' name='org' placeholder='' value='%s'></label>"
|
|
||||||
"<label>Bucket (optional)<input id='bucket' name='bucket' placeholder='' value='%s'></label>"
|
|
||||||
"<label>Token<input id='token' name='token' placeholder=''></label>"
|
|
||||||
"<button type='submit'>Save & Connect</button>"
|
|
||||||
"</form>"
|
|
||||||
"<p class='muted'>After saving, the device will connect to your Wi-Fi network. "
|
|
||||||
"The access point will automatically shut down shortly afterward.</p>"
|
|
||||||
"</div>"
|
|
||||||
"<script>"
|
|
||||||
"async function load(){try{"
|
|
||||||
" let r=await fetch('/scan'); if(!r.ok) throw 0; let a=await r.json();"
|
|
||||||
" let s=document.getElementById('nets'); s.innerHTML='';"
|
|
||||||
" a.sort((x,y)=>y.rssi-x.rssi);"
|
|
||||||
" a.forEach(n=>{let o=document.createElement('option');"
|
|
||||||
" o.value=n.ssid; o.textContent=n.ssid+' ('+n.rssi+' dBm)'; s.appendChild(o);});"
|
|
||||||
" if(a.length && !document.getElementById('ssid').value){"
|
|
||||||
" document.getElementById('ssid').value=a[0].ssid;}"
|
|
||||||
"}catch(e){console.log(e);}}"
|
|
||||||
"document.getElementById('refresh').onclick=load;"
|
|
||||||
"document.getElementById('nets').onchange=function(){document.getElementById('ssid').value=this.value;};"
|
|
||||||
"load();"
|
|
||||||
"</script>"
|
|
||||||
"</body></html>";
|
|
||||||
|
|
||||||
static const char saved_html[] =
|
|
||||||
"<!doctype html><html><head><meta charset='utf-8'/>"
|
|
||||||
"<meta name='viewport' content='width=device-width,initial-scale=1'/>"
|
|
||||||
"<title>Saved</title></head><body>"
|
|
||||||
"<h1>✔️ Saved</h1>"
|
|
||||||
"<p>The credentials have been saved. The device is now connecting to your Wi-Fi…</p>"
|
|
||||||
"<script>setTimeout(()=>location.href='/status',1500)</script>"
|
|
||||||
"</body></html>";
|
|
||||||
|
|
||||||
static const char status_tpl[] =
|
|
||||||
"<!doctype html><html><head><meta charset='utf-8'/>"
|
|
||||||
"<meta name='viewport' content='width=device-width,initial-scale=1'/>"
|
|
||||||
"<title>Status</title></head><body>"
|
|
||||||
"<h1>Connection Status</h1>"
|
|
||||||
"<p>%s</p>"
|
|
||||||
"<p><a href='/'>Back</a></p>"
|
|
||||||
"</body></html>";
|
|
||||||
|
|
||||||
// ---------- simple URL decoder ----------
|
|
||||||
static int hexval(char c){ if(c>='0'&&c<='9')return c-'0'; if(c>='a'&&c<='f')return 10+c-'a'; if(c>='A'&&c<='F')return 10+c-'A'; return -1; }
|
|
||||||
static void urldecode(char* s){
|
|
||||||
char* o = s;
|
|
||||||
for(char* i=s; *i; ++i){
|
|
||||||
if(*i=='+'){ *o++=' '; }
|
|
||||||
else if(*i=='%' && hexval(i[1])>=0 && hexval(i[2])>=0){ *o++ = (char)((hexval(i[1])<<4)|hexval(i[2])); i+=2; }
|
|
||||||
else { *o++=*i; }
|
|
||||||
}
|
|
||||||
*o='\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- HTTP Handlers ----------
|
|
||||||
static esp_err_t root_get(httpd_req_t *req) {
|
|
||||||
char *org = NULL, *bucket = NULL, *token = NULL;
|
|
||||||
if (!storage_get_effective_influx(&org, &bucket, &token)) {
|
|
||||||
org = strdup("");
|
|
||||||
bucket = strdup("");
|
|
||||||
token = strdup("");
|
|
||||||
if (!org || !bucket || !token) {
|
|
||||||
if (org) free(org);
|
|
||||||
if (bucket) free(bucket);
|
|
||||||
if (token) free(token);
|
|
||||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "oom");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *dev_raw = NULL;
|
|
||||||
if (!storage_get_effective_device_name(&dev_raw)) {
|
|
||||||
dev_raw = strdup("");
|
|
||||||
if (!dev_raw) {
|
|
||||||
free(org); free(bucket); free(token);
|
|
||||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "oom");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *dev_esc = html_escape(dev_raw);
|
|
||||||
char *org_esc = html_escape(org ? org : "");
|
|
||||||
char *bucket_esc = html_escape(bucket ? bucket : "");
|
|
||||||
if (!dev_esc || !org_esc || !bucket_esc) {
|
|
||||||
if (dev_esc) free(dev_esc);
|
|
||||||
if (org_esc) free(org_esc);
|
|
||||||
if (bucket_esc) free(bucket_esc);
|
|
||||||
free(org); free(bucket); free(token);
|
|
||||||
free(dev_raw);
|
|
||||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "oom");
|
|
||||||
}
|
|
||||||
|
|
||||||
int need = snprintf(NULL, 0, form_html_tpl,
|
|
||||||
s_ap_ssid,
|
|
||||||
dev_esc,
|
|
||||||
org_esc,
|
|
||||||
bucket_esc);
|
|
||||||
if (need < 0) {
|
|
||||||
free(org); free(bucket); free(token);
|
|
||||||
free(dev_raw);
|
|
||||||
free(dev_esc); free(org_esc); free(bucket_esc);
|
|
||||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "format error");
|
|
||||||
}
|
|
||||||
|
|
||||||
char *page = (char*)malloc((size_t)need + 1);
|
|
||||||
if (!page) {
|
|
||||||
free(org); free(bucket); free(token);
|
|
||||||
free(dev_raw);
|
|
||||||
free(dev_esc); free(org_esc); free(bucket_esc);
|
|
||||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "oom");
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(page, (size_t)need + 1, form_html_tpl,
|
|
||||||
s_ap_ssid,
|
|
||||||
dev_esc,
|
|
||||||
org_esc,
|
|
||||||
bucket_esc);
|
|
||||||
|
|
||||||
httpd_resp_set_type(req, "text/html; charset=utf-8");
|
|
||||||
esp_err_t r = httpd_resp_send(req, page, HTTPD_RESP_USE_STRLEN);
|
|
||||||
|
|
||||||
free(page);
|
|
||||||
free(org); free(bucket); free(token);
|
|
||||||
free(dev_raw);
|
|
||||||
free(dev_esc); free(org_esc); free(bucket_esc);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t captive_ok(httpd_req_t *req) {
|
|
||||||
EventBits_t bits = xEventGroupGetBits(s_wifi_events);
|
|
||||||
if (bits & s_BIT_GOTIP) {
|
|
||||||
httpd_resp_set_status(req, "204 No Content");
|
|
||||||
httpd_resp_set_type(req, "text/plain");
|
|
||||||
return httpd_resp_send(req, NULL, 0);
|
|
||||||
} else {
|
|
||||||
httpd_resp_set_type(req, "text/html; charset=utf-8");
|
|
||||||
const char msg[] = "<html><body>OK</body></html>";
|
|
||||||
return httpd_resp_send(req, msg, HTTPD_RESP_USE_STRLEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t status_get(httpd_req_t *req) {
|
|
||||||
EventBits_t bits = xEventGroupGetBits(s_wifi_events);
|
|
||||||
const char *msg = (bits & s_BIT_GOTIP) ? "✅ Connected to external Wi-Fi."
|
|
||||||
: (bits & s_BIT_FAIL) ? "❌ Connection failed. Please check your credentials."
|
|
||||||
: "⏳ Connecting...";
|
|
||||||
|
|
||||||
int need = snprintf(NULL, 0, status_tpl, msg);
|
|
||||||
if (need < 0) return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "format error");
|
|
||||||
|
|
||||||
char *page = (char*)malloc((size_t)need + 1);
|
|
||||||
if (!page) return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "oom");
|
|
||||||
|
|
||||||
snprintf(page, (size_t)need + 1, status_tpl, msg);
|
|
||||||
httpd_resp_set_type(req, "text/html; charset=utf-8");
|
|
||||||
esp_err_t r = httpd_resp_send(req, page, HTTPD_RESP_USE_STRLEN);
|
|
||||||
free(page);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t favicon_get(httpd_req_t *req) {
|
|
||||||
httpd_resp_set_status(req, "204 No Content");
|
|
||||||
httpd_resp_set_type(req, "image/x-icon");
|
|
||||||
return httpd_resp_send(req, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The rest of the logic (save_post, scan_get, start_http, portal_http_start, portal_http_stop)
|
|
||||||
// remains IDENTICAL to your provided code above — only text/UI changes were made.
|
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
{
|
{
|
||||||
"folders": [
|
"folders": [
|
||||||
{ "name": "nanopsx-root", "path": "."},
|
{
|
||||||
{ "name": "firmware", "path": "firmware" },
|
"name": "nanopsx-root",
|
||||||
{ "name": "desktop-app", "path": "desktop-app" }
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firmware",
|
||||||
|
"path": "firmware"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
// Optional: hier könntest du später projektweite Settings reinpacken
|
// Optional: hier könntest du später projektweite Settings reinpacken
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
- mit Administratorrechten wird angefordert …
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
INFLUXDB_INIT_URL=http://localhost:8086
|
||||||
|
INFLUXDB_INIT_TOKEN=0946c41441a85088b38d39da6ed06d75a
|
||||||
|
INFLUXDB_INIT_ADMIN_TOKEN=0946c41441a85088b38d39da6ed06d75a
|
||||||
|
INFLUXDB_INIT_MODE=setup
|
||||||
|
INFLUXDB_INIT_USERNAME=admin
|
||||||
|
INFLUXDB_INIT_PASSWORD=12345678
|
||||||
|
INFLUXDB_INIT_ORG=myorg
|
||||||
|
INFLUXDB_INIT_BUCKET=nanoPSX
|
||||||
|
|
||||||
|
|
||||||
|
INFLUX_URL=http://localhost:8086
|
||||||
|
INFLUX_TOKEN=0946c41441a85088b38d39da6ed06d75a
|
||||||
|
INFLUX_ORG=myorg
|
||||||
|
INFLUX_BUCKET=nanoPSX
|
||||||
@@ -0,0 +1,383 @@
|
|||||||
|
:: =============================================================
|
||||||
|
:: Selbst-Elevation – verlangt Adminrechte, falls nicht vorhanden
|
||||||
|
:: =============================================================
|
||||||
|
@echo off
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo -> Neustart mit Administratorrechten wird angefordert …
|
||||||
|
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
:: -------------------- ab hier läuft das Skript erhöht --------------------
|
||||||
|
chcp 65001 >nul
|
||||||
|
title Installation: InfluxDB 2
|
||||||
|
setlocal DisableDelayedExpansion
|
||||||
|
|
||||||
|
echo ==============================================================
|
||||||
|
echo InfluxDB 2 und InfluxDBmDNS werden installiert - bitte etwas Geduld …
|
||||||
|
echo ==============================================================
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 0) Konstanten / Service-Namen
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
set "TARGET=C:\Program Files\InfluxDB2"
|
||||||
|
set "PD=%ProgramData%\InfluxDB2"
|
||||||
|
set "SVC_DB=InfluxDB2"
|
||||||
|
set "SVC_MDNS=InfluxDBmDNS"
|
||||||
|
set "EXE_DB=%TARGET%\influxd.exe"
|
||||||
|
set "EXE_MDNS=%TARGET%\InfluxDBmDNS.exe"
|
||||||
|
set "NSSM=%TARGET%\nssm.exe"
|
||||||
|
set "LOG_DB_OUT=%PD%\influxd.out.log"
|
||||||
|
set "LOG_DB_ERR=%PD%\influxd.err.log"
|
||||||
|
set "LOG_MDNS_OUT=%PD%\influxmdns.out.log"
|
||||||
|
set "LOG_MDNS_ERR=%PD%\influxmdns.err.log"
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 1) Konfigurationsdatei einlesen
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [1/7] Konfiguration einlesen …
|
||||||
|
set "CFG_FILE=%~dp0config.txt"
|
||||||
|
if not exist "%CFG_FILE%" (
|
||||||
|
echo [FEHLER] %CFG_FILE% nicht gefunden!
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
for /f "usebackq eol=# tokens=1* delims==" %%A in ("%CFG_FILE%") do (
|
||||||
|
if not "%%~A"=="" (
|
||||||
|
for /f "tokens=* delims= " %%X in ("%%~B") do set "%%~A=%%~X"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
rem Kurz-Aliase
|
||||||
|
set "URL=%INFLUXDB_INIT_URL%"
|
||||||
|
set "TOKEN=%INFLUXDB_INIT_TOKEN%"
|
||||||
|
set "ADMIN_TOKEN=%INFLUXDB_INIT_ADMIN_TOKEN%"
|
||||||
|
set "USER=%INFLUXDB_INIT_USERNAME%"
|
||||||
|
set "PASS=%INFLUXDB_INIT_PASSWORD%"
|
||||||
|
set "ORG=%INFLUXDB_INIT_ORG%"
|
||||||
|
set "BUCKET=%INFLUXDB_INIT_BUCKET%"
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 2) Dateien kopieren (mit Prozess-Check und Retry-Logik)
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [2/7] Dateien vorbereiten und kopieren …
|
||||||
|
|
||||||
|
echo Zielordner "%TARGET%" anlegen …
|
||||||
|
if not exist "%TARGET%" (
|
||||||
|
mkdir "%TARGET%" || (
|
||||||
|
echo [FEHLER] Ordner konnte nicht angelegt werden.
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo ProgramData-Ordner sicherstellen …
|
||||||
|
if not exist "%PD%" (
|
||||||
|
mkdir "%PD%" >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [FEHLER] Konnte "%PD%" nicht anlegen.
|
||||||
|
echo Bitte Rechte/Antivirus/Ransomware-Schutz pruefen.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Schreibrechte testen
|
||||||
|
echo test>"%PD%\write.test" 2>nul
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [FEHLER] Keine Schreibrechte in "%PD%".
|
||||||
|
echo Bitte Rechte/Antivirus/Ransomware-Schutz pruefen.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Beende blockierende Prozesse …
|
||||||
|
rem --- sicher mDNS stoppen (falls vorhanden/laufend), sonst nur Prozess killen ---
|
||||||
|
call :stop_service_safe "%SVC_MDNS%" 30 "InfluxDBmDNS.exe"
|
||||||
|
|
||||||
|
rem --- sicher DB stoppen (falls vorhanden/laufend), sonst nur Prozess killen ---
|
||||||
|
call :stop_service_safe "%SVC_DB%" 30 "influxd.exe"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
rem Selbstkopie vermeiden, falls Script bereits aus dem Zielordner gestartet wurde
|
||||||
|
if /I "%~dp0"=="%TARGET%\" (
|
||||||
|
echo Quelle und Ziel sind identisch - Kopieren uebersprungen.
|
||||||
|
set "copy_success=1"
|
||||||
|
goto :copy_done
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Dateien kopieren (max. 3 Versuche) …
|
||||||
|
set "copy_success=0"
|
||||||
|
for /l %%i in (1,1,3) do (
|
||||||
|
xcopy "%~dp0*" "%TARGET%\" /E /I /Y /Q >nul && (
|
||||||
|
set "copy_success=1"
|
||||||
|
goto :copy_done
|
||||||
|
)
|
||||||
|
if %%i lss 3 (
|
||||||
|
echo Versuch %%i fehlgeschlagen - neuer Versuch in 2 Sekunden …
|
||||||
|
timeout /t 2 >nul
|
||||||
|
echo Erneutes Beenden blockierender Prozesse …
|
||||||
|
taskkill /IM influxd.exe /F >nul 2>&1
|
||||||
|
taskkill /IM InfluxDBmDNS.exe /F >nul 2>&1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
:copy_done
|
||||||
|
if %copy_success% neq 1 (
|
||||||
|
echo [FEHLER] Kopieren nach 3 Versuchen fehlgeschlagen.
|
||||||
|
echo Mögliche Ursachen:
|
||||||
|
echo 1. Dateien werden durch andere Prozesse gesperrt
|
||||||
|
echo 2. Fehlende Administratorrechte
|
||||||
|
echo 3. Antivirensoftware blockiert den Zugriff
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 3) PATH anpassen
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [3/7] PATH-Variable prüfen …
|
||||||
|
set "PATH_PAD=;%PATH%;"
|
||||||
|
echo %PATH_PAD% | find /I ";%TARGET%;" >nul
|
||||||
|
if errorlevel 1 (
|
||||||
|
setx PATH "%PATH%;%TARGET%" >nul && echo -> Ordner in PATH eingetragen.
|
||||||
|
) else (
|
||||||
|
echo -> Ordner bereits im PATH.
|
||||||
|
)
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 4) Dienste installieren/aktualisieren (NSSM), konfigurieren & Recovery
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [4a/7] Dienste anlegen/aktualisieren …
|
||||||
|
|
||||||
|
if not exist "%NSSM%" (
|
||||||
|
echo [FEHLER] nssm.exe nicht gefunden in "%TARGET%".
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
rem ---- InfluxDB2 (install/update & config) ----
|
||||||
|
sc.exe query "%SVC_DB%" >nul 2>&1
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
echo -> Dienst "%SVC_DB%" existiert bereits. Aktualisiere Eigenschaften …
|
||||||
|
"%NSSM%" set "%SVC_DB%" Application "%EXE_DB%" >nul
|
||||||
|
) else (
|
||||||
|
echo -> Installiere neuen Dienst "%SVC_DB%" …
|
||||||
|
"%NSSM%" install "%SVC_DB%" "%EXE_DB%"
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [FEHLER] NSSM-Installation von %SVC_DB% fehlgeschlagen.
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppDirectory "%TARGET%" >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppStdout "%LOG_DB_OUT%" >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppStderr "%LOG_DB_ERR%" >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppRotateFiles 1 >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppRotateOnline 1 >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppRotateBytes 10485760 >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppStopMethodSkip 0 >nul
|
||||||
|
sc.exe config "%SVC_DB%" start= delayed-auto obj= "LocalSystem" DisplayName= "InfluxDB 2 Server" >nul
|
||||||
|
sc.exe failure "%SVC_DB%" reset= 86400 actions= restart/5000/restart/5000/restart/600000 >nul
|
||||||
|
|
||||||
|
rem ---- InfluxDBmDNS (install/update & config) ----
|
||||||
|
sc.exe query "%SVC_MDNS%" >nul 2>&1
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
echo -> Dienst "%SVC_MDNS%" existiert bereits. Aktualisiere Eigenschaften …
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" Application "%EXE_MDNS%" >nul
|
||||||
|
) else (
|
||||||
|
echo -> Installiere neuen Dienst "%SVC_MDNS%" …
|
||||||
|
"%NSSM%" install "%SVC_MDNS%" "%EXE_MDNS%"
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [FEHLER] NSSM-Installation von %SVC_MDNS% fehlgeschlagen.
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppDirectory "%TARGET%" >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppStdout "%LOG_MDNS_OUT%" >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppStderr "%LOG_MDNS_ERR%" >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppRotateFiles 1 >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppRotateOnline 1 >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppRotateBytes 10485760 >nul
|
||||||
|
"%NSSM%" set "%SVC_MDNS%" AppStopMethodSkip 0 >nul
|
||||||
|
"%NSSM%" set "%SVC_DB%" AppPriority HIGH_PRIORITY_CLASS
|
||||||
|
|
||||||
|
rem Starttyp/Anzeigename & Abhängigkeit (mDNS nach DB)
|
||||||
|
sc.exe config "%SVC_MDNS%" start= delayed-auto obj= "LocalSystem" DisplayName= "InfluxDB2 Announce" depend= %SVC_DB% >nul
|
||||||
|
sc.exe failure "%SVC_MDNS%" reset= 86400 actions= restart/5000/restart/5000/restart/600000 >nul
|
||||||
|
|
||||||
|
sc.exe config "%SVC_DB%" depend= Tcpip
|
||||||
|
|
||||||
|
rem Windows-Firewall: InfluxDB-Port zulassen (eingehend)
|
||||||
|
netsh advfirewall firewall show rule name="InfluxDB 8086 In" | findstr /I "No rules match" >nul && ^
|
||||||
|
netsh advfirewall firewall add rule name="InfluxDB 8086 In" dir=in action=allow protocol=TCP localport=8086 >nul
|
||||||
|
|
||||||
|
rem mDNS (UDP 5353) zulassen (eingehend)
|
||||||
|
netsh advfirewall firewall show rule name="mDNS 5353 In" | findstr /I "No rules match" >nul && ^
|
||||||
|
netsh advfirewall firewall add rule name="mDNS 5353 In" dir=in action=allow protocol=UDP localport=5353 >nul
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo [4b/7] Energieeinstellungen fuer 24/7-Betrieb setzen ...
|
||||||
|
|
||||||
|
:: Hibernate komplett aus (verhindert unerwartetes Wegnicken/Hiberfile)
|
||||||
|
powercfg /hibernate off
|
||||||
|
|
||||||
|
:: Auf Netzbetrieb: niemals Standby, niemals Monitor-Sleep
|
||||||
|
powercfg -change -standby-timeout-ac 0
|
||||||
|
powercfg -change -monitor-timeout-ac 0
|
||||||
|
|
||||||
|
:: Optional: auch auf Akku, falls Laptop
|
||||||
|
powercfg -change -standby-timeout-dc 0
|
||||||
|
powercfg -change -monitor-timeout-dc 0
|
||||||
|
|
||||||
|
:: High Performance/Ultimative Leistung aktivieren (wo vorhanden)
|
||||||
|
powercfg -setactive SCHEME_MIN
|
||||||
|
|
||||||
|
:: Diagnose ausgeben (sollte zeigen, dass kein Standby-Timer gesetzt ist)
|
||||||
|
powercfg /getactivescheme
|
||||||
|
powercfg /query
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 5) Dienste starten (Re-Start) + Health-Check
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [5/7] Dienste starten …
|
||||||
|
|
||||||
|
echo Stoppe ggf. laufende Instanzen …
|
||||||
|
sc.exe stop "%SVC_DB%" >nul 2>&1
|
||||||
|
sc.exe stop "%SVC_MDNS%" >nul 2>&1
|
||||||
|
timeout /t 2 >nul
|
||||||
|
|
||||||
|
echo Starte InfluxDB2 …
|
||||||
|
sc.exe start "%SVC_DB%" >nul 2>&1
|
||||||
|
timeout /t 2 >nul
|
||||||
|
|
||||||
|
echo Starte InfluxDBmDNS (haengt von InfluxDB2 ab) …
|
||||||
|
sc.exe start "%SVC_MDNS%" >nul 2>&1
|
||||||
|
timeout /t 2 >nul
|
||||||
|
|
||||||
|
echo Fuehre kurzen Health-Check durch (nicht fatal) …
|
||||||
|
powershell -NoProfile -Command ^
|
||||||
|
"$u=[uri]'%URL%'; try { $r=Invoke-WebRequest -Uri ($u.AbsoluteUri.TrimEnd('/') + '/health') -UseBasicParsing -TimeoutSec 5; if($r.StatusCode -ge 200 -and $r.StatusCode -lt 500){ exit 0 } else { exit 1 } } catch { exit 1 }" ^
|
||||||
|
>nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [WARNUNG] /health nicht bestaetigt - fahre fort. Pruefe später ggf. "%LOG_DB_ERR%"
|
||||||
|
)
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 6) InfluxDB2 konfigurieren (Setup falls noch nicht erfolgt)
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [6/7] InfluxDB2 konfigurieren …
|
||||||
|
|
||||||
|
echo Warte, bis %URL% erreichbar ist …
|
||||||
|
powershell -NoProfile -Command ^
|
||||||
|
"$u=[uri]'%URL%'; while(-not (Test-NetConnection $u.Host -Port $u.Port).TcpTestSucceeded){Start-Sleep 2}"
|
||||||
|
|
||||||
|
echo Fuehre Setup/Provisioning aus …
|
||||||
|
"%TARGET%\influx.exe" setup --host "%URL%" --token "%ADMIN_TOKEN%" --org "%ORG%" --bucket "%BUCKET%" --username "%USER%" --password "%PASS%" --retention 0 --force
|
||||||
|
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
rem 6) Dashboard-Template importieren
|
||||||
|
rem ----------------------------------------------------------------
|
||||||
|
echo.
|
||||||
|
echo [7/7] Dashboard-Template importieren …
|
||||||
|
timeout /t 8 /nobreak >nul
|
||||||
|
"%TARGET%\influx.exe" apply -f "%~dp0template.yml" --force yes --host "%URL%" --org "%ORG%" --token "%ADMIN_TOKEN%"
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [FEHLER] Dashboard-Import fehlgeschlagen.
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
rem -- Web-UI oeffnen (robust) --
|
||||||
|
set "OPEN_URL=%URL%"
|
||||||
|
rem erst Explorer versuchen
|
||||||
|
start "" "%OPEN_URL%" >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
rem Fallback: PowerShell
|
||||||
|
powershell -NoProfile -Command "Start-Process '%OPEN_URL%'" >nul 2>&1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ==============================================================
|
||||||
|
echo Installation abgeschlossen! --^> %URL%
|
||||||
|
echo Benutzer: %USER%
|
||||||
|
echo Hinweis: Passwort steht in der config.txt
|
||||||
|
echo ==============================================================
|
||||||
|
echo Druecken Sie eine beliebige Taste, um das Fenster zu schliessen …
|
||||||
|
pause >nul
|
||||||
|
|
||||||
|
endlocal & exit /b
|
||||||
|
|
||||||
|
|
||||||
|
:: -------------------------------------------------
|
||||||
|
:: stop_service_safe <Dienstname> <TimeoutSek> <Prozess.exe>
|
||||||
|
:: - Stoppt Dienst nur wenn RUNNING
|
||||||
|
:: - Wartet bis STOPPED (oder bis Timeout)
|
||||||
|
:: - Killt zusätzlich den Prozessnamen (falls noch da)
|
||||||
|
:: -------------------------------------------------
|
||||||
|
:stop_service_safe
|
||||||
|
setlocal EnableDelayedExpansion
|
||||||
|
set "SVC=%~1"
|
||||||
|
set "WTO=%~2"
|
||||||
|
set "PROC=%~3"
|
||||||
|
|
||||||
|
rem Existiert der Dienst?
|
||||||
|
sc.exe query "%SVC%" >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
rem Dienst existiert nicht -> nur Prozess ggf. killen
|
||||||
|
goto :kill_only
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Läuft der Dienst?
|
||||||
|
sc.exe query "%SVC%" | find /I "STATE" | find /I "RUNNING" >nul
|
||||||
|
if not errorlevel 1 (
|
||||||
|
sc.exe stop "%SVC%" >nul 2>&1
|
||||||
|
call :wait_service "%SVC%" "%WTO%"
|
||||||
|
)
|
||||||
|
|
||||||
|
:kill_only
|
||||||
|
rem Prozess ggf. beenden (Fehler egal, Output stumm)
|
||||||
|
tasklist /FI "IMAGENAME eq %PROC%" | find /I "%PROC%" >nul 2>&1 && ^
|
||||||
|
taskkill /IM "%PROC%" /F >nul 2>&1
|
||||||
|
|
||||||
|
endlocal & exit /b 0
|
||||||
|
|
||||||
|
:: -------------------------------------------------
|
||||||
|
:: wait_service <Dienstname> <TimeoutSek>
|
||||||
|
:: - Wartet bis STATE = STOPPED (oder Dienst fehlt)
|
||||||
|
:: - Bricht nach Timeout Sekunden ab (ohne Fehler)
|
||||||
|
:: -------------------------------------------------
|
||||||
|
:wait_service
|
||||||
|
setlocal EnableDelayedExpansion
|
||||||
|
set "WSVC=%~1"
|
||||||
|
set "WTO=%~2"
|
||||||
|
if "%WTO%"=="" set "WTO=30"
|
||||||
|
|
||||||
|
set /a tries=0
|
||||||
|
:ws_loop
|
||||||
|
rem Falls Dienst gar nicht (mehr) existiert -> fertig
|
||||||
|
sc.exe query "%WSVC%" >nul 2>&1
|
||||||
|
if errorlevel 1 goto :ws_done
|
||||||
|
|
||||||
|
rem Prüfen ob STOPPED
|
||||||
|
sc.exe query "%WSVC%" | find /I "STATE" | find /I "STOPPED" >nul
|
||||||
|
if not errorlevel 1 goto :ws_done
|
||||||
|
|
||||||
|
set /a tries+=1
|
||||||
|
if !tries! LSS %WTO% (timeout /t 1 >nul & goto :ws_loop)
|
||||||
|
|
||||||
|
:ws_done
|
||||||
|
endlocal & exit /b 0
|
||||||
|
|
||||||
|
|
||||||