diff --git a/examples/mqtt-dashboard/client/main.css b/examples/mqtt-dashboard/client/main.css index 00ef676029..5f87bfca84 100644 --- a/examples/mqtt-dashboard/client/main.css +++ b/examples/mqtt-dashboard/client/main.css @@ -1 +1 @@ -/*! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:Inter var,Helvetica,sans-serif;font-feature-settings:"cv11","ss01";font-variation-settings:"opsz" 32}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.pointer-events-auto{pointer-events:auto}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.inset-0{inset:0}.right-4{right:1rem}.top-0{top:0}.top-4{top:1rem}.isolate{isolation:isolate}.z-10{z-index:10}.z-\[48\]{z-index:48}.m-4{margin:1rem}.mx-auto{margin-left:auto;margin-right:auto}.my-1{margin-top:.25rem;margin-bottom:.25rem}.my-3{margin-top:.75rem;margin-bottom:.75rem}.my-5{margin-top:1.25rem;margin-bottom:1.25rem}.mb-1{margin-bottom:.25rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.ml-3{margin-left:.75rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-1{margin-top:.25rem}.mt-3{margin-top:.75rem}.mt-5{margin-top:1.25rem}.mt-7{margin-top:1.75rem}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.table{display:table}.grid{display:grid}.hidden{display:none}.h-12{height:3rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-0{width:0}.w-11{width:2.75rem}.w-4{width:1rem}.w-5{width:1.25rem}.w-6{width:1.5rem}.w-96{width:24rem}.w-full{width:100%}.min-w-full{min-width:100%}.max-w-md{max-width:28rem}.max-w-sm{max-width:24rem}.flex-1{flex:1 1 0%}.flex-none{flex:none}.flex-shrink-0{flex-shrink:0}.shrink{flex-shrink:1}.flex-grow{flex-grow:1}.translate-x-0{--tw-translate-x:0px}.translate-x-0,.translate-x-5{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-5{--tw-translate-x:1.25rem}.translate-y-0{--tw-translate-y:0px}.translate-y-0,.translate-y-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-y-2{--tw-translate-y:0.5rem}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.place-content-end{place-content:end}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-center{align-items:center}.justify-end{justify-content:flex-end}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-1\.5{gap:.375rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.gap-x-2{-moz-column-gap:.5rem;column-gap:.5rem}.gap-x-4{-moz-column-gap:1rem;column-gap:1rem}.-space-x-px>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(-1px*var(--tw-space-x-reverse));margin-left:calc(-1px*(1 - var(--tw-space-x-reverse)))}.space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(1rem*var(--tw-space-x-reverse));margin-left:calc(1rem*(1 - var(--tw-space-x-reverse)))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-gray-200>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(229 231 235/var(--tw-divide-opacity))}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-scroll{overflow:scroll}.truncate{overflow:hidden;white-space:nowrap}.text-ellipsis,.truncate{text-overflow:ellipsis}.whitespace-nowrap{white-space:nowrap}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.rounded-xl{border-radius:.75rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-b-2{border-bottom-width:2px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity))}.border-slate-200{--tw-border-opacity:1;border-color:rgb(226 232 240/var(--tw-border-opacity))}.border-slate-300{--tw-border-opacity:1;border-color:rgb(203 213 225/var(--tw-border-opacity))}.border-transparent{border-color:#0000}.bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity))}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity))}.bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity))}.bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.bg-slate-200{--tw-bg-opacity:1;background-color:rgb(226 232 240/var(--tw-bg-opacity))}.bg-slate-300{--tw-bg-opacity:1;background-color:rgb(203 213 225/var(--tw-bg-opacity))}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity))}.stroke-cyan-600{stroke:#0891b2}.stroke-1{stroke-width:1}.p-3{padding:.75rem}.p-4{padding:1rem}.p-5{padding:1.25rem}.p-8{padding:2rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.py-0{padding-top:0;padding-bottom:0}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pr-3{padding-right:.75rem}.pt-0{padding-top:0}.pt-0\.5{padding-top:.125rem}.pt-2{padding-top:.5rem}.text-center{text-align:center}.align-middle{vertical-align:middle}.text-2xl{font-size:1.5rem;line-height:2rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-light{font-weight:300}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.tracking-tight{letter-spacing:-.025em}.tracking-wide{letter-spacing:.025em}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.text-green-400{--tw-text-opacity:1;color:rgb(74 222 128/var(--tw-text-opacity))}.text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity))}.text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity))}.text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity))}.text-slate-300{--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity))}.text-slate-400{--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity))}.text-slate-500{--tw-text-opacity:1;color:rgb(100 116 139/var(--tw-text-opacity))}.text-slate-700{--tw-text-opacity:1;color:rgb(51 65 85/var(--tw-text-opacity))}.text-slate-900{--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity))}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 #0000001a,0 1px 2px -1px #0000001a;--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.shadow,.shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a;--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.shadow-md{--tw-shadow:0 4px 6px -1px #0000001a,0 2px 4px -2px #0000001a;--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.shadow-md,.shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 2px 0 #0000000d;--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.outline{outline-style:solid}.ring-0{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-0,.ring-1{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-inset{--tw-ring-inset:inset}.ring-black{--tw-ring-opacity:1;--tw-ring-color:rgb(0 0 0/var(--tw-ring-opacity))}.ring-gray-300{--tw-ring-opacity:1;--tw-ring-color:rgb(209 213 219/var(--tw-ring-opacity))}.ring-green-300{--tw-ring-opacity:1;--tw-ring-color:rgb(134 239 172/var(--tw-ring-opacity))}.ring-red-300{--tw-ring-opacity:1;--tw-ring-color:rgb(252 165 165/var(--tw-ring-opacity))}.ring-yellow-300{--tw-ring-opacity:1;--tw-ring-color:rgb(253 224 71/var(--tw-ring-opacity))}.ring-opacity-5{--tw-ring-opacity:0.05}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}.duration-300{transition-duration:.3s}.ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}.ease-out{transition-timing-function:cubic-bezier(0,0,.2,1)}.placeholder\:text-gray-400::-moz-placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.placeholder\:text-gray-400::placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.hover\:bg-blue-500:hover{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity))}.hover\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity))}.hover\:bg-slate-100:hover{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.hover\:text-gray-500:hover{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.focus\:z-20:focus{z-index:20}.focus\:outline-none:focus{outline:2px solid #0000;outline-offset:2px}.focus\:outline-offset-0:focus{outline-offset:0}.focus\:ring-0:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\:outline:focus-visible{outline-style:solid}.focus-visible\:outline-2:focus-visible{outline-width:2px}.focus-visible\:outline-offset-0:focus-visible{outline-offset:0}.focus-visible\:outline-blue-600:focus-visible{outline-color:#2563eb}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-blue-400:disabled{--tw-bg-opacity:1;background-color:rgb(96 165 250/var(--tw-bg-opacity))}.disabled\:bg-gray-100:disabled{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.disabled\:text-gray-500:disabled{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}@media (prefers-color-scheme:dark){.dark\:border-gray-800{--tw-border-opacity:1;border-color:rgb(31 41 55/var(--tw-border-opacity))}.dark\:bg-slate-900{--tw-bg-opacity:1;background-color:rgb(15 23 42/var(--tw-bg-opacity))}.dark\:text-gray-200{--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity))}.dark\:text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}}@media (min-width:640px){.sm\:flex{display:flex}.sm\:flex-1{flex:1 1 0%}.sm\:translate-x-0{--tw-translate-x:0px}.sm\:translate-x-0,.sm\:translate-x-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:translate-x-2{--tw-translate-x:0.5rem}.sm\:translate-y-0{--tw-translate-y:0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:items-start{align-items:flex-start}.sm\:items-end{align-items:flex-end}.sm\:items-center{align-items:center}.sm\:justify-between{justify-content:space-between}.sm\:p-6{padding:1.5rem}.sm\:text-sm{font-size:.875rem;line-height:1.25rem}.sm\:leading-6{line-height:1.5rem}}@media (min-width:1024px){.lg\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}} \ No newline at end of file +/*! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:Inter var,Helvetica,sans-serif;font-feature-settings:"cv11","ss01";font-variation-settings:"opsz" 32}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.pointer-events-auto{pointer-events:auto}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.inset-0{inset:0}.right-4{right:1rem}.top-0{top:0}.top-4{top:1rem}.isolate{isolation:isolate}.z-10{z-index:10}.z-\[48\]{z-index:48}.m-4{margin:1rem}.mx-auto{margin-left:auto;margin-right:auto}.my-1{margin-top:.25rem;margin-bottom:.25rem}.my-3{margin-top:.75rem;margin-bottom:.75rem}.my-5{margin-top:1.25rem;margin-bottom:1.25rem}.mb-1{margin-bottom:.25rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.ml-3{margin-left:.75rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-1{margin-top:.25rem}.mt-3{margin-top:.75rem}.mt-5{margin-top:1.25rem}.mt-7{margin-top:1.75rem}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.table{display:table}.grid{display:grid}.hidden{display:none}.h-12{height:3rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-0{width:0}.w-11{width:2.75rem}.w-4{width:1rem}.w-5{width:1.25rem}.w-6{width:1.5rem}.w-96{width:24rem}.w-full{width:100%}.min-w-full{min-width:100%}.max-w-md{max-width:28rem}.max-w-sm{max-width:24rem}.flex-1{flex:1 1 0%}.flex-none{flex:none}.flex-shrink-0{flex-shrink:0}.shrink{flex-shrink:1}.flex-grow{flex-grow:1}.translate-x-0{--tw-translate-x:0px}.translate-x-0,.translate-x-5{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-5{--tw-translate-x:1.25rem}.translate-y-0{--tw-translate-y:0px}.translate-y-0,.translate-y-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-y-2{--tw-translate-y:0.5rem}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.place-content-end{place-content:end}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-center{align-items:center}.justify-end{justify-content:flex-end}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-1\.5{gap:.375rem}.gap-2{gap:.5rem}.gap-4{gap:1rem}.gap-x-2{-moz-column-gap:.5rem;column-gap:.5rem}.gap-x-4{-moz-column-gap:1rem;column-gap:1rem}.-space-x-px>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(-1px*var(--tw-space-x-reverse));margin-left:calc(-1px*(1 - var(--tw-space-x-reverse)))}.space-x-4>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(1rem*var(--tw-space-x-reverse));margin-left:calc(1rem*(1 - var(--tw-space-x-reverse)))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-gray-200>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(229 231 235/var(--tw-divide-opacity))}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-scroll{overflow:scroll}.truncate{overflow:hidden;white-space:nowrap}.text-ellipsis,.truncate{text-overflow:ellipsis}.whitespace-nowrap{white-space:nowrap}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.rounded-xl{border-radius:.75rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-b-2{border-bottom-width:2px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity))}.border-slate-200{--tw-border-opacity:1;border-color:rgb(226 232 240/var(--tw-border-opacity))}.border-slate-300{--tw-border-opacity:1;border-color:rgb(203 213 225/var(--tw-border-opacity))}.border-transparent{border-color:#0000}.bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity))}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.bg-green-100{--tw-bg-opacity:1;background-color:rgb(220 252 231/var(--tw-bg-opacity))}.bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity))}.bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.bg-slate-200{--tw-bg-opacity:1;background-color:rgb(226 232 240/var(--tw-bg-opacity))}.bg-slate-300{--tw-bg-opacity:1;background-color:rgb(203 213 225/var(--tw-bg-opacity))}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.bg-yellow-100{--tw-bg-opacity:1;background-color:rgb(254 249 195/var(--tw-bg-opacity))}.stroke-cyan-600{stroke:#0891b2}.stroke-1{stroke-width:1}.p-3{padding:.75rem}.p-4{padding:1rem}.p-5{padding:1.25rem}.p-8{padding:2rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.py-0{padding-top:0;padding-bottom:0}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pr-3{padding-right:.75rem}.pt-0{padding-top:0}.pt-0\.5{padding-top:.125rem}.pt-2{padding-top:.5rem}.text-center{text-align:center}.align-middle{vertical-align:middle}.text-2xl{font-size:1.5rem;line-height:2rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-light{font-weight:300}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.tracking-tight{letter-spacing:-.025em}.tracking-wide{letter-spacing:.025em}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.text-green-400{--tw-text-opacity:1;color:rgb(74 222 128/var(--tw-text-opacity))}.text-green-900{--tw-text-opacity:1;color:rgb(20 83 45/var(--tw-text-opacity))}.text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity))}.text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity))}.text-slate-300{--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity))}.text-slate-400{--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity))}.text-slate-500{--tw-text-opacity:1;color:rgb(100 116 139/var(--tw-text-opacity))}.text-slate-700{--tw-text-opacity:1;color:rgb(51 65 85/var(--tw-text-opacity))}.text-slate-900{--tw-text-opacity:1;color:rgb(15 23 42/var(--tw-text-opacity))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.text-yellow-900{--tw-text-opacity:1;color:rgb(113 63 18/var(--tw-text-opacity))}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 #0000001a,0 1px 2px -1px #0000001a;--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.shadow,.shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a;--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.shadow-md{--tw-shadow:0 4px 6px -1px #0000001a,0 2px 4px -2px #0000001a;--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.shadow-md,.shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 2px 0 #0000000d;--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.outline{outline-style:solid}.ring-0{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-0,.ring-1{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-inset{--tw-ring-inset:inset}.ring-black{--tw-ring-opacity:1;--tw-ring-color:rgb(0 0 0/var(--tw-ring-opacity))}.ring-gray-300{--tw-ring-opacity:1;--tw-ring-color:rgb(209 213 219/var(--tw-ring-opacity))}.ring-green-300{--tw-ring-opacity:1;--tw-ring-color:rgb(134 239 172/var(--tw-ring-opacity))}.ring-red-300{--tw-ring-opacity:1;--tw-ring-color:rgb(252 165 165/var(--tw-ring-opacity))}.ring-yellow-300{--tw-ring-opacity:1;--tw-ring-color:rgb(253 224 71/var(--tw-ring-opacity))}.ring-opacity-5{--tw-ring-opacity:0.05}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}.duration-300{transition-duration:.3s}.ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}.ease-out{transition-timing-function:cubic-bezier(0,0,.2,1)}.placeholder\:text-gray-400::-moz-placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.placeholder\:text-gray-400::placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.hover\:bg-blue-500:hover{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity))}.hover\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity))}.hover\:bg-slate-100:hover{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.hover\:text-gray-500:hover{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.focus\:z-20:focus{z-index:20}.focus\:outline-none:focus{outline:2px solid #0000;outline-offset:2px}.focus\:outline-offset-0:focus{outline-offset:0}.focus\:ring-0:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\:outline:focus-visible{outline-style:solid}.focus-visible\:outline-2:focus-visible{outline-width:2px}.focus-visible\:outline-offset-0:focus-visible{outline-offset:0}.focus-visible\:outline-blue-600:focus-visible{outline-color:#2563eb}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-blue-400:disabled{--tw-bg-opacity:1;background-color:rgb(96 165 250/var(--tw-bg-opacity))}.disabled\:bg-gray-100:disabled{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.disabled\:text-gray-500:disabled{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}@media (prefers-color-scheme:dark){.dark\:border-gray-800{--tw-border-opacity:1;border-color:rgb(31 41 55/var(--tw-border-opacity))}.dark\:bg-slate-900{--tw-bg-opacity:1;background-color:rgb(15 23 42/var(--tw-bg-opacity))}.dark\:text-gray-200{--tw-text-opacity:1;color:rgb(229 231 235/var(--tw-text-opacity))}.dark\:text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}}@media (min-width:640px){.sm\:flex{display:flex}.sm\:flex-1{flex:1 1 0%}.sm\:translate-x-0{--tw-translate-x:0px}.sm\:translate-x-0,.sm\:translate-x-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:translate-x-2{--tw-translate-x:0.5rem}.sm\:translate-y-0{--tw-translate-y:0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:items-start{align-items:flex-start}.sm\:items-end{align-items:flex-end}.sm\:items-center{align-items:center}.sm\:justify-between{justify-content:space-between}.sm\:p-6{padding:1.5rem}.sm\:text-sm{font-size:.875rem;line-height:1.25rem}.sm\:leading-6{line-height:1.5rem}}@media (min-width:1024px){.lg\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}} \ No newline at end of file diff --git a/examples/mqtt-dashboard/device/Makefile b/examples/mqtt-dashboard/device/Makefile index bbdb7b6dd9..6bad4d937c 100644 --- a/examples/mqtt-dashboard/device/Makefile +++ b/examples/mqtt-dashboard/device/Makefile @@ -1,7 +1,7 @@ PROG ?= example # Program we are building DELETE = rm -rf # Command to remove files OUT ?= -o $(PROG) # Compiler argument for output file -SOURCES = main.c mongoose.c # Source code files +SOURCES = main.c net.c mongoose.c # Source code files CFLAGS = -W -Wall -Wextra -g -I. # Build options # Mongoose build options. See https://mongoose.ws/documentation/#build-options diff --git a/examples/mqtt-dashboard/device/main.c b/examples/mqtt-dashboard/device/main.c index 00b16c0e01..0c2837568e 100644 --- a/examples/mqtt-dashboard/device/main.c +++ b/examples/mqtt-dashboard/device/main.c @@ -1,33 +1,7 @@ // Copyright (c) 2023 Cesanta Software Limited // All rights reserved -// -// Example MQTT client. It performs the following steps: -// -// To enable SSL/TLS, see https://mongoose.ws/tutorials/tls/#how-to-build -#include "mongoose.h" - -#define DEVICE_ID_LEN 10 -#define ROOT_TOPIC_LEN 30 -#define KEEP_ALIVE_INTERVAL 60 -#define MQTT_SERVER_URL "mqtt://broker.hivemq.com:1883" -#define DEFAULT_ROOT_TOPIC "topic_mg_device" - -static const char *s_url; -static char *s_device_id; -static const char *s_root_topic; -static int s_qos = 1; // MQTT QoS -static struct mg_connection *s_conn; // Client connection -static struct mg_rpc *s_rpc_head = NULL; - -struct device_config { - bool led_status; - uint8_t led_pin; - uint8_t brightness; - uint8_t log_level; -}; - -static struct device_config s_device_config; +#include "net.h" // Handle interrupts, like Ctrl-C static int s_signo; @@ -35,250 +9,17 @@ static void signal_handler(int signo) { s_signo = signo; } -static void generate_device_id(void) { - char tmp[DEVICE_ID_LEN + 1]; - mg_random_str(tmp, DEVICE_ID_LEN); - s_device_id = strdup(tmp); -} - -static size_t print_fw_status(void (*out)(char, void *), void *ptr, - va_list *ap) { - int fw = va_arg(*ap, int); - return mg_xprintf(out, ptr, "{%m:%d,%m:%c%lx%c,%m:%u,%m:%u}", - MG_ESC("status"), mg_ota_status(fw), MG_ESC("crc32"), '"', - mg_ota_crc32(fw), '"', MG_ESC("size"), mg_ota_size(fw), - MG_ESC("timestamp"), mg_ota_timestamp(fw)); -} - -static void publish_status(struct mg_connection *c) { - int status_topic_len = 50; - char* status_topic = calloc(status_topic_len, sizeof(char)); - if (!status_topic) { - MG_ERROR(("Out of memory")); - return; - } - mg_snprintf(status_topic, status_topic_len, "%s/%s/status", s_root_topic, - s_device_id); - struct mg_str pubt = mg_str(status_topic); - struct mg_mqtt_opts pub_opts; - memset(&pub_opts, 0, sizeof(pub_opts)); - pub_opts.topic = pubt; - int json_len = 400; - char *device_status_json; - device_status_json = calloc(json_len, sizeof(char)); - if (!device_status_json) { - MG_ERROR(("Out of memory")); - return; - } - mg_snprintf(device_status_json, json_len, - "{%m:%m,%m:{%m:%m,%m:%s,%m:%hhu,%m:%hhu,%m:%hhu,%m:%M,%m:%M}}", - MG_ESC("method"), MG_ESC("status.notify"), MG_ESC("params"), - MG_ESC("status"), MG_ESC("online"), MG_ESC("led_status"), - s_device_config.led_status ? "true" : "false", MG_ESC("led_pin"), - s_device_config.led_pin, MG_ESC("brightness"), - s_device_config.brightness, MG_ESC(("log_level")), - s_device_config.log_level, MG_ESC(("crnt_fw")), print_fw_status, - MG_FIRMWARE_CURRENT, MG_ESC(("prev_fw")), print_fw_status, - MG_FIRMWARE_PREVIOUS); - struct mg_str data = mg_str(device_status_json); - pub_opts.message = data; - pub_opts.qos = s_qos, pub_opts.retain = true; - mg_mqtt_pub(c, &pub_opts); - MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr, - (int) pubt.len, pubt.ptr)); - free(device_status_json); - free(status_topic); -} - -static void publish_response(struct mg_connection *c, char *buf, size_t len) { - int tx_topic_len = 50; - char* tx_topic = calloc(tx_topic_len, sizeof(char)); - if (!tx_topic) { - MG_ERROR(("Out of memory")); - return; - } - mg_snprintf(tx_topic, tx_topic_len, "%s/%s/tx", s_root_topic, - s_device_id); - struct mg_str pubt = mg_str(tx_topic); - struct mg_mqtt_opts pub_opts; - memset(&pub_opts, 0, sizeof(pub_opts)); - pub_opts.topic = pubt; - struct mg_str data = mg_str_n(buf, len); - pub_opts.message = data; - pub_opts.qos = s_qos; - mg_mqtt_pub(c, &pub_opts); - MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr, - (int) pubt.len, pubt.ptr)); - free(tx_topic); -} - -static void subscribe(struct mg_connection *c) { - int rx_topic_len = 50; - char* rx_topic = calloc(rx_topic_len, sizeof(char)); - if (!rx_topic) { - MG_ERROR(("Out of memory")); - return; - } - mg_snprintf(rx_topic, rx_topic_len, "%s/%s/rx", s_root_topic, - s_device_id); - struct mg_str subt = mg_str(rx_topic); - struct mg_mqtt_opts sub_opts; - memset(&sub_opts, 0, sizeof(sub_opts)); - sub_opts.topic = subt; - sub_opts.qos = s_qos; - mg_mqtt_sub(c, &sub_opts); - MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.ptr)); - free(rx_topic); -} - -static void rpc_config_set(struct mg_rpc_req *r) { - bool tmp_status, ok; - long tmp_brightness, tmp_level, tmp_pin; - - ok = mg_json_get_bool(r->frame, "$.params.led_status", &tmp_status); - if (ok) s_device_config.led_status = tmp_status; - - tmp_brightness = mg_json_get_long(r->frame, "$.params.brightness", -1); - if (tmp_brightness >= 0) s_device_config.brightness = tmp_brightness; - - tmp_level = mg_json_get_long(r->frame, "$.params.log_level", -1); - if (tmp_level >= 0) s_device_config.log_level = tmp_level; - - tmp_pin = mg_json_get_long(r->frame, "$.params.led_pin", -1); - if (tmp_pin > 0) s_device_config.led_pin = tmp_pin; - - mg_rpc_ok(r, "%m", MG_ESC("ok")); -} - -static void rpc_ota_commit(struct mg_rpc_req *r) { - if (mg_ota_commit()) { - mg_rpc_ok(r, "%m", MG_ESC("ok")); - } else { - mg_rpc_err(r, 1, "Failed to commit the firmware"); - } -} - -static void rpc_device_reset(struct mg_rpc_req *r) { - mg_rpc_ok(r, "%m", MG_ESC("ok")); -} - -static void rpc_ota_rollback(struct mg_rpc_req *r) { - if (mg_ota_rollback()) { - mg_rpc_ok(r, "%m", MG_ESC("ok")); - } else { - mg_rpc_err(r, 1, "Failed to rollback to the previous firmware"); - } -} - -static void rpc_ota_upload(struct mg_rpc_req *r) { - long ofs = mg_json_get_long(r->frame, "$.params.offset", -1); - long tot = mg_json_get_long(r->frame, "$.params.total", -1); - int len; - char *file_chunk = mg_json_get_b64(r->frame, "$.params.chunk", &len); - if (!file_chunk) { - mg_rpc_err(r, 1, "Error processing the binary chunk."); - return; - } - struct mg_str data = mg_str_n(file_chunk, len); - if (ofs < 0 || tot < 0) { - mg_rpc_err(r, 1, "offset and total not set"); - } else if (ofs == 0 && mg_ota_begin((size_t) tot) == false) { - mg_rpc_err(r, 1, "mg_ota_begin(%ld) failed\n", tot); - } else if (data.len > 0 && mg_ota_write(data.ptr, data.len) == false) { - mg_rpc_err(r, 1, "mg_ota_write(%lu) @%ld failed\n", data.len, ofs); - mg_ota_end(); - } else if (data.len == 0 && mg_ota_end() == false) { - mg_rpc_err(r, 1, "mg_ota_end() failed\n", tot); - } else { - mg_rpc_ok(r, "%m", MG_ESC("ok")); - if (data.len == 0) { - // Successful mg_ota_end() called, schedule device reboot - mg_timer_add(s_conn->mgr, 500, 0, (void (*)(void *)) mg_device_reset, - NULL); - } - } - free(file_chunk); -} - -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - if (ev == MG_EV_OPEN) { - MG_INFO(("%lu CREATED", c->id)); - // c->is_hexdumping = 1; - } else if (ev == MG_EV_CONNECT) { - MG_INFO(("Device ID is connected %s", s_device_id)); - } else if (ev == MG_EV_ERROR) { - // On error, log error message - MG_ERROR(("%lu ERROR %s", c->id, (char *) ev_data)); - } else if (ev == MG_EV_MQTT_OPEN) { - // MQTT connect is successful - MG_INFO(("%lu CONNECTED to %s", c->id, s_url)); - subscribe(c); - publish_status(c); - } else if (ev == MG_EV_MQTT_MSG) { - // When we get echo response, print it - struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; - if (!mg_strcmp(mm->topic, mg_str("ota.upload"))) { - MG_INFO(("%lu RECEIVED %.*s <- %.*s", c->id, (int) mm->data.len, - mm->data.ptr, (int) mm->topic.len, mm->topic.ptr)); - } - struct mg_iobuf io = {0, 0, 0, 512}; - struct mg_rpc_req r = {&s_rpc_head, 0, mg_pfn_iobuf, &io, 0, mm->data}; - mg_rpc_process(&r); - if (io.buf) { - publish_response(c, (char *) io.buf, io.len); - publish_status(c); - } - mg_iobuf_free(&io); - } else if (ev == MG_EV_CLOSE) { - MG_INFO(("%lu CLOSED", c->id)); - s_conn = NULL; // Mark that we're closed - } - (void) fn_data; -} - -// Timer function - recreate client connection if it is closed -static void timer_fn(void *arg) { - struct mg_mgr *mgr = (struct mg_mgr *) arg; - char status_topic[50]; - memset(status_topic, 0, sizeof(status_topic)); - mg_snprintf(status_topic, sizeof(status_topic), "%s/%s/status", s_root_topic, - s_device_id); - char msg[200]; - memset(msg, 0, sizeof(msg)); - mg_snprintf(msg, sizeof(msg), "{%m:%m,%m:{%m:%m}}", MG_ESC("method"), - MG_ESC("status.notify"), MG_ESC("params"), MG_ESC("status"), - MG_ESC("offline")); - - struct mg_mqtt_opts opts = {.clean = true, - .qos = s_qos, - .topic = mg_str(status_topic), - .version = 4, - .keepalive = KEEP_ALIVE_INTERVAL, - .retain = true, - .message = mg_str(msg)}; - if (s_conn == NULL) s_conn = mg_mqtt_connect(mgr, s_url, &opts, fn, NULL); -} - -static void timer_keepalive(void *arg) { - mg_mqtt_send_header(s_conn, MQTT_CMD_PINGREQ, 0, 0); - (void) arg; -} - int main(int argc, char *argv[]) { struct mg_mgr mgr; - int i; - int pingreq_interval_ms = KEEP_ALIVE_INTERVAL * 1000 - 500; - s_url = MQTT_SERVER_URL; - s_root_topic = DEFAULT_ROOT_TOPIC; // Parse command-line flags - for (i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-u") == 0 && argv[i + 1] != NULL) { - s_url = argv[++i]; + g_url = argv[++i]; } else if (strcmp(argv[i], "-i") == 0 && argv[i + 1] != NULL) { - s_device_id = strdup(argv[++i]); + g_device_id = strdup(argv[++i]); } else if (strcmp(argv[i], "-t") == 0 && argv[i + 1] != NULL) { - s_root_topic = argv[++i]; + g_root_topic = argv[++i]; } else if (strcmp(argv[i], "-v") == 0 && argv[i + 1] != NULL) { mg_log_set(atoi(argv[++i])); } else { @@ -292,22 +33,17 @@ int main(int argc, char *argv[]) { signal(SIGINT, signal_handler); // Setup signal handlers - exist event signal(SIGTERM, signal_handler); // manager loop on SIGINT and SIGTERM - if (!s_device_id) generate_device_id(); + mg_log_set(MG_LL_DEBUG); // Set debug log level + mg_mgr_init(&mgr); + + web_init(&mgr); + while (s_signo == 0) { + mg_mgr_poll(&mgr, 50); + } - // Configure JSON-RPC functions we're going to handle - mg_rpc_add(&s_rpc_head, mg_str("config.set"), rpc_config_set, NULL); - mg_rpc_add(&s_rpc_head, mg_str("ota.commit"), rpc_ota_commit, NULL); - mg_rpc_add(&s_rpc_head, mg_str("device.reset"), rpc_device_reset, NULL); - mg_rpc_add(&s_rpc_head, mg_str("ota.rollback"), rpc_ota_rollback, NULL); - mg_rpc_add(&s_rpc_head, mg_str("ota.upload"), rpc_ota_upload, NULL); + mg_mgr_free(&mgr); + web_destroy(); + MG_INFO(("Exiting on signal %d", s_signo)); - mg_mgr_init(&mgr); - mg_timer_add(&mgr, 3000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr); - mg_timer_add(&mgr, pingreq_interval_ms, MG_TIMER_REPEAT, timer_keepalive, - &mgr); - while (s_signo == 0) mg_mgr_poll(&mgr, 1000); // Event loop, 1s timeout - mg_mgr_free(&mgr); // Finished, cleanup - mg_rpc_del(&s_rpc_head, NULL); // Deallocate RPC handlers - free(s_device_id); return 0; } diff --git a/examples/mqtt-dashboard/device/net.c b/examples/mqtt-dashboard/device/net.c new file mode 100644 index 0000000000..feb5cd25e9 --- /dev/null +++ b/examples/mqtt-dashboard/device/net.c @@ -0,0 +1,280 @@ +// Copyright (c) 2023 Cesanta Software Limited +// All rights reserved + +#include "net.h" + +char *g_url = MQTT_SERVER_URL; +char *g_device_id; +char *g_root_topic; +static uint8_t s_qos = 1; // MQTT QoS +static struct mg_connection *s_conn; // Client connection +static struct mg_rpc *s_rpc_head = NULL; + +struct device_config { + bool led_status; + uint8_t led_pin; + uint8_t brightness; + uint8_t log_level; +}; + +static struct device_config s_device_config; + +// This is for newlib and TLS (mbedTLS) +uint64_t mg_now(void) { + return mg_millis(); +} + +static void generate_device_id(void) { + char tmp[DEVICE_ID_LEN + 1]; + tmp[DEVICE_ID_LEN] = '\0'; + mg_random_str(tmp, DEVICE_ID_LEN); + g_device_id = strdup(tmp); +} + +static size_t print_fw_status(void (*out)(char, void *), void *ptr, + va_list *ap) { + int fw = va_arg(*ap, int); + return mg_xprintf(out, ptr, "{%m:%d,%m:%c%lx%c,%m:%u,%m:%u}", + MG_ESC("status"), mg_ota_status(fw), MG_ESC("crc32"), '"', + mg_ota_crc32(fw), '"', MG_ESC("size"), mg_ota_size(fw), + MG_ESC("timestamp"), mg_ota_timestamp(fw)); +} + +static void publish_status(struct mg_connection *c) { + int status_topic_len = 50; + char *status_topic = calloc(status_topic_len, sizeof(char)); + if (!status_topic) { + MG_ERROR(("Out of memory")); + return; + } + mg_snprintf(status_topic, status_topic_len, "%s/%s/status", g_root_topic, + g_device_id); + struct mg_str pubt = mg_str(status_topic); + struct mg_mqtt_opts pub_opts; + memset(&pub_opts, 0, sizeof(pub_opts)); + pub_opts.topic = pubt; + int json_len = 400; + char *device_status_json; + device_status_json = calloc(json_len, sizeof(char)); + if (!device_status_json) { + MG_ERROR(("Out of memory")); + return; + } + mg_snprintf(device_status_json, json_len, + "{%m:%m,%m:{%m:%m,%m:%s,%m:%hhu,%m:%hhu,%m:%hhu,%m:%M,%m:%M}}", + MG_ESC("method"), MG_ESC("status.notify"), MG_ESC("params"), + MG_ESC("status"), MG_ESC("online"), MG_ESC("led_status"), + s_device_config.led_status ? "true" : "false", MG_ESC("led_pin"), + s_device_config.led_pin, MG_ESC("brightness"), + s_device_config.brightness, MG_ESC(("log_level")), + s_device_config.log_level, MG_ESC(("crnt_fw")), print_fw_status, + MG_FIRMWARE_CURRENT, MG_ESC(("prev_fw")), print_fw_status, + MG_FIRMWARE_PREVIOUS); + struct mg_str data = mg_str(device_status_json); + pub_opts.message = data; + pub_opts.qos = s_qos, pub_opts.retain = true; + mg_mqtt_pub(c, &pub_opts); + MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr, + (int) pubt.len, pubt.ptr)); + free(device_status_json); + free(status_topic); +} + +static void publish_response(struct mg_connection *c, char *buf, size_t len) { + int tx_topic_len = 50; + char *tx_topic = calloc(tx_topic_len, sizeof(char)); + if (!tx_topic) { + MG_ERROR(("Out of memory")); + return; + } + mg_snprintf(tx_topic, tx_topic_len, "%s/%s/tx", g_root_topic, g_device_id); + struct mg_str pubt = mg_str(tx_topic); + struct mg_mqtt_opts pub_opts; + memset(&pub_opts, 0, sizeof(pub_opts)); + pub_opts.topic = pubt; + struct mg_str data = mg_str_n(buf, len); + pub_opts.message = data; + pub_opts.qos = s_qos; + mg_mqtt_pub(c, &pub_opts); + MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr, + (int) pubt.len, pubt.ptr)); + free(tx_topic); +} + +static void subscribe(struct mg_connection *c) { + int rx_topic_len = 50; + char *rx_topic = calloc(rx_topic_len, sizeof(char)); + if (!rx_topic) { + MG_ERROR(("Out of memory")); + return; + } + mg_snprintf(rx_topic, rx_topic_len, "%s/%s/rx", g_root_topic, g_device_id); + struct mg_str subt = mg_str(rx_topic); + struct mg_mqtt_opts sub_opts; + memset(&sub_opts, 0, sizeof(sub_opts)); + sub_opts.topic = subt; + sub_opts.qos = s_qos; + mg_mqtt_sub(c, &sub_opts); + MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.ptr)); + free(rx_topic); +} + +static void rpc_config_set(struct mg_rpc_req *r) { + bool tmp_status, ok; + int8_t tmp_brightness, tmp_level, tmp_pin; + + ok = mg_json_get_bool(r->frame, "$.params.led_status", &tmp_status); + if (ok) s_device_config.led_status = tmp_status; + + tmp_brightness = (int8_t) mg_json_get_long(r->frame, "$.params.brightness", -1); + if (tmp_brightness >= 0) s_device_config.brightness = tmp_brightness; + + tmp_level = (int8_t) mg_json_get_long(r->frame, "$.params.log_level", -1); + if (tmp_level >= 0) { + s_device_config.log_level = tmp_level; + mg_log_set(s_device_config.log_level); + } + + tmp_pin = (int8_t) mg_json_get_long(r->frame, "$.params.led_pin", -1); + if (tmp_pin > 0) s_device_config.led_pin = tmp_pin; + + mg_rpc_ok(r, "%m", MG_ESC("ok")); +} + +static void rpc_ota_commit(struct mg_rpc_req *r) { + if (mg_ota_commit()) { + mg_rpc_ok(r, "%m", MG_ESC("ok")); + } else { + mg_rpc_err(r, 1, "Failed to commit the firmware"); + } +} + +static void rpc_device_reset(struct mg_rpc_req *r) { + mg_rpc_ok(r, "%m", MG_ESC("ok")); + mg_timer_add(s_conn->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL); +} + +static void rpc_ota_rollback(struct mg_rpc_req *r) { + if (mg_ota_rollback()) { + mg_rpc_ok(r, "%m", MG_ESC("ok")); + } else { + mg_rpc_err(r, 1, "Failed to rollback to the previous firmware"); + } +} + +static void rpc_ota_upload(struct mg_rpc_req *r) { + long ofs = mg_json_get_long(r->frame, "$.params.offset", -1); + long tot = mg_json_get_long(r->frame, "$.params.total", -1); + int len; + char *file_chunk = mg_json_get_b64(r->frame, "$.params.chunk", &len); + if (!file_chunk) { + mg_rpc_err(r, 1, "Error processing the binary chunk."); + return; + } + struct mg_str data = mg_str_n(file_chunk, len); + if (ofs < 0 || tot < 0) { + mg_rpc_err(r, 1, "offset and total not set"); + } else if (ofs == 0 && mg_ota_begin((size_t) tot) == false) { + mg_rpc_err(r, 1, "mg_ota_begin(%ld) failed\n", tot); + } else if (data.len > 0 && mg_ota_write(data.ptr, data.len) == false) { + mg_rpc_err(r, 1, "mg_ota_write(%lu) @%ld failed\n", data.len, ofs); + mg_ota_end(); + } else if (data.len == 0 && mg_ota_end() == false) { + mg_rpc_err(r, 1, "mg_ota_end() failed\n", tot); + } else { + mg_rpc_ok(r, "%m", MG_ESC("ok")); + if (data.len == 0) { + // Successful mg_ota_end() called, schedule device reboot + mg_timer_add(s_conn->mgr, 500, 0, (void (*)(void *)) mg_device_reset, + NULL); + } + } + free(file_chunk); +} + +static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { + if (ev == MG_EV_OPEN) { + MG_INFO(("%lu CREATED", c->id)); + // c->is_hexdumping = 1; + } else if (ev == MG_EV_CONNECT) { + MG_INFO(("Device ID is connected %s", g_device_id)); + } else if (ev == MG_EV_ERROR) { + // On error, log error message + MG_ERROR(("%lu ERROR %s", c->id, (char *) ev_data)); + } else if (ev == MG_EV_MQTT_OPEN) { + // MQTT connect is successful + MG_INFO(("%lu CONNECTED to %s", c->id, g_url)); + subscribe(c); + publish_status(c); + } else if (ev == MG_EV_MQTT_MSG) { + // When we get echo response, print it + struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; + if (mm->data.len < 1024) { + MG_INFO(("%lu RECEIVED %.*s <- %.*s", c->id, (int) mm->data.len, + mm->data.ptr, (int) mm->topic.len, mm->topic.ptr)); + } + struct mg_iobuf io = {0, 0, 0, 512}; + struct mg_rpc_req r = {&s_rpc_head, 0, mg_pfn_iobuf, &io, 0, mm->data}; + mg_rpc_process(&r); + if (io.buf) { + publish_response(c, (char *) io.buf, io.len); + publish_status(c); + } + mg_iobuf_free(&io); + } else if (ev == MG_EV_CLOSE) { + MG_INFO(("%lu CLOSED", c->id)); + s_conn = NULL; // Mark that we're closed + } + (void) fn_data; +} + +// Timer function - recreate client connection if it is closed +static void timer_fn(void *arg) { + struct mg_mgr *mgr = (struct mg_mgr *) arg; + char status_topic[50]; + memset(status_topic, 0, sizeof(status_topic)); + mg_snprintf(status_topic, sizeof(status_topic), "%s/%s/status", g_root_topic, + g_device_id); + char msg[200]; + memset(msg, 0, sizeof(msg)); + mg_snprintf(msg, sizeof(msg), "{%m:%m,%m:{%m:%m}}", MG_ESC("method"), + MG_ESC("status.notify"), MG_ESC("params"), MG_ESC("status"), + MG_ESC("offline")); + + struct mg_mqtt_opts opts = {.clean = true, + .qos = s_qos, + .topic = mg_str(status_topic), + .version = 4, + .keepalive = KEEP_ALIVE_INTERVAL, + .retain = true, + .message = mg_str(msg)}; + if (s_conn == NULL) s_conn = mg_mqtt_connect(mgr, g_url, &opts, fn, NULL); +} + +static void timer_keepalive(void *arg) { + mg_mqtt_send_header(s_conn, MQTT_CMD_PINGREQ, 0, 0); + (void) arg; +} + +void web_init(struct mg_mgr *mgr) { + int pingreq_interval_ms = KEEP_ALIVE_INTERVAL * 1000 - 500; + if (!g_device_id) generate_device_id(); + if (!g_root_topic) g_root_topic = DEFAULT_ROOT_TOPIC; + s_device_config.log_level = (uint8_t) mg_log_level; + + // Configure JSON-RPC functions we're going to handle + mg_rpc_add(&s_rpc_head, mg_str("config.set"), rpc_config_set, NULL); + mg_rpc_add(&s_rpc_head, mg_str("ota.commit"), rpc_ota_commit, NULL); + mg_rpc_add(&s_rpc_head, mg_str("device.reset"), rpc_device_reset, NULL); + mg_rpc_add(&s_rpc_head, mg_str("ota.rollback"), rpc_ota_rollback, NULL); + mg_rpc_add(&s_rpc_head, mg_str("ota.upload"), rpc_ota_upload, NULL); + + mg_timer_add(mgr, 3000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, mgr); + mg_timer_add(mgr, pingreq_interval_ms, MG_TIMER_REPEAT, timer_keepalive, + mgr); +} + +void web_destroy() { + mg_rpc_del(&s_rpc_head, NULL); // Deallocate RPC handlers + free(g_device_id); +} \ No newline at end of file diff --git a/examples/mqtt-dashboard/device/net.h b/examples/mqtt-dashboard/device/net.h new file mode 100644 index 0000000000..af09e5b7c6 --- /dev/null +++ b/examples/mqtt-dashboard/device/net.h @@ -0,0 +1,30 @@ +// Copyright (c) 2023 Cesanta Software Limited +// All rights reserved +#pragma once + +#include "mongoose.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MQTT_DASHBOARD +#define MQTT_DASHBOARD 1 +#endif + +#define DEVICE_ID_LEN 10 +#define ROOT_TOPIC_LEN 30 +#define KEEP_ALIVE_INTERVAL 60 +#define MQTT_SERVER_URL "mqtt://broker.hivemq.com:1883" +#define DEFAULT_ROOT_TOPIC "topic_mg_device" + +extern char *g_url; +extern char *g_device_id; +extern char *g_root_topic; + +void web_init(struct mg_mgr *mgr); +void web_destroy(); + +#ifdef __cplusplus +} +#endif diff --git a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/Makefile b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/Makefile index da8c0650af..a7a0a122ec 100644 --- a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/Makefile +++ b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/Makefile @@ -16,12 +16,18 @@ CFLAGS += -DHTTP_URL=\"http://0.0.0.0/\" -DHTTPS_URL=\"https://0.0.0.0/\" ifeq ($(OS),Windows_NT) RM = cmd /C del /Q /F /S + SYMLINK = cmd /C mklink /H else RM = rm -rf + SYMLINK = ln -sf endif all build example: firmware.bin +device_dashboard: clean_bin device_dashboard_net firmware.bin + +mqtt_dashboard: clean_bin mqtt_dashboard_net firmware.bin + firmware.bin: firmware.elf arm-none-eabi-objcopy -O binary $< $@ @@ -45,6 +51,17 @@ CFLAGS += -DMBEDTLS_CONFIG_FILE=\"mbedtls_config.h\" mbedtls/library/*.c firmware.elf: mbedtls endif +device_dashboard_net: + $(SYMLINK) ../../device-dashboard/net.c net.c + $(SYMLINK) ../../device-dashboard/net.h net.h + +mqtt_dashboard_net: + $(SYMLINK) ../../mqtt-dashboard/device/net.c net.c + $(SYMLINK) ../../mqtt-dashboard/device/net.h net.h + +clean_bin: + $(RM) firmware.elf firmware.bin + # Automated remote test. Requires env variable VCON_API_KEY set. See https://vcon.io/automated-firmware-tests/ DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/10 update: firmware.bin diff --git a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c index 6f73c9f074..46b60bde6a 100644 --- a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c @@ -37,6 +37,14 @@ int main(void) { uart_init(UART_DEBUG, 115200); // Initialise debug printf ethernet_init(); // Initialise ethernet pins + #ifdef MQTT_DASHBOARD + // User can customise the MQTT url, device ID or the root topic below + #define DEVICE_ID "H723ZG" + g_url = MQTT_SERVER_URL; + g_device_id = DEVICE_ID; + g_root_topic = DEFAULT_ROOT_TOPIC; + #endif + MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000)); struct mg_mgr mgr; // Initialise diff --git a/mongoose.c b/mongoose.c index 9066656af9..c84251807b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3988,8 +3988,8 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, } break; case MQTT_CMD_PUBLISH: { - MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) mm.topic.len, - mm.topic.ptr, (int) mm.data.len, mm.data.ptr)); + /*MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) mm.topic.len, + mm.topic.ptr, (int) mm.data.len, mm.data.ptr));*/ if (mm.qos > 0) { uint16_t id = mg_ntohs(mm.id); uint32_t remaining_len = sizeof(id); diff --git a/src/mqtt.c b/src/mqtt.c index 2d959f9596..a1cba49c4f 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -451,8 +451,8 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, } break; case MQTT_CMD_PUBLISH: { - MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) mm.topic.len, - mm.topic.ptr, (int) mm.data.len, mm.data.ptr)); + /*MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) mm.topic.len, + mm.topic.ptr, (int) mm.data.len, mm.data.ptr));*/ if (mm.qos > 0) { uint16_t id = mg_ntohs(mm.id); uint32_t remaining_len = sizeof(id);