Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

846 lines
23 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Remove wifi info from File: dir, Node: Top, This is the top of the INFO tree. This is the Info main menu (aka directory node). A few useful Info commands: 'q' quits; '?' lists all Info commands; 'h' starts the Info tutorial; 'mTexinfo RET' visits the Texinfo manual, etc. * Menu: Basics * Common options: (coreutils)Common options. * Coreutils: (coreutils). Core GNU (file, text, shell) utilities. * Date input formats: (coreutils)Date input formats. * Ed: (ed). The GNU line editor * File permissions: (coreutils)File permissions. Access modes. * Finding files: (find). Operating on files matching certain criteria. C++ libraries * autosprintf: (autosprintf). Support for printf format strings in C++. Compression * Gzip: (gzip). General (de)compression of files (lzw). Development * SSIP: (ssip). Speech Synthesis Interface Protocol. * Speech Dispatcher: (speech-dispatcher). Speech Dispatcher. * libffi: (libffi). Portable foreign-function interface library. DOS * Mtools: (mtools). Mtools: utilities to access DOS disks in Unix. Editors * nano: (nano). Small and friendly text editor. General Commands * Screen: (screen). Full-screen window manager. GNU Gettext Utilities * autopoint: (gettext)autopoint Invocation. Copy gettext infrastructure. * envsubst: (gettext)envsubst Invocation. Expand environment variables. * gettextize: (gettext)gettextize Invocation. Prepare a package for gettext. * gettext: (gettext). GNU gettext utilities. * ISO3166: (gettext)Country Codes. ISO 3166 country codes. * ISO639: (gettext)Language Codes. ISO 639 language codes. * msgattrib: (gettext)msgattrib Invocation. Select part of a PO file. * msgcat: (gettext)msgcat Invocation. Combine several PO files. * msgcmp: (gettext)msgcmp Invocation. Compare a PO file and template. * msgcomm: (gettext)msgcomm Invocation. Match two PO files. * msgconv: (gettext)msgconv Invocation. Convert PO file to encoding. * msgen: (gettext)msgen Invocation. Create an English PO file. * msgexec: (gettext)msgexec Invocation. Process a PO file. * msgfilter: (gettext)msgfilter Invocation. Pipe a PO file through a filter. * msgfmt: (gettext)msgfmt Invocation. Make MO files out of PO files. * msggrep: (gettext)msggrep Invocation. Select part of a PO file. * msginit: (gettext)msginit Invocation. Create a fresh PO file. * msgmerge: (gettext)msgmerge Invocation. Update a PO file from template. * msgunfmt: (gettext)msgunfmt Invocation. Uncompile MO file into PO file. * msguniq: (gettext)msguniq Invocation. Unify duplicates for PO file. * ngettext: (gettext)ngettext Invocation. Translate a message with plural. * xgettext: (gettext)xgettext Invocation. Extract strings into a PO file. GNU organization * Maintaining Findutils: (find-maint). Maintaining GNU findutils GNU Utilities * dirmngr-client: (gnupg). X.509 CRL and OCSP client. * dirmngr: (gnupg). X.509 CRL and OCSP server. * gpg: (gnupg1). OpenPGP encryption and signing tool (v1). * gpg-agent: (gnupg). The secret key daemon. * gpg2: (gnupg). OpenPGP encryption and signing tool. * gpgsm: (gnupg). S/MIME encryption and signing tool. Individual utilities * aclocal-invocation: (automake-1.15)aclocal Invocation. Generating aclocal.m4. * arch: (coreutils)arch invocation. Print machine hardware name. * automake-invocation: (automake-1.15)automake Invocation. Generating Makefile.in. * base32: (coreutils)base32 invocation. Base32 encode/decode data. * base64: (coreutils)base64 invocation. Base64 encode/decode data. * basename: (coreutils)basename invocation. Strip directory and suffix. * bibtex: (web2c)bibtex invocation. Maintaining bibliographies. * cat: (coreutils)cat invocation. Concatenate and write files. * chcon: (coreutils)chcon invocation. Change SELinux CTX of files. * chgrp: (coreutils)chgrp invocation. Change file groups. * chmod: (coreutils)chmod invocation. Change access permissions. * chown: (coreutils)chown invocation. Change file owners and groups. * chroot: (coreutils)chroot invocation. Specify the root directory. * cksum: (coreutils)cksum invocation. Print POSIX CRC checksum. * cmp: (diffutils)Invoking cmp. Compare 2 files byte by byte. * comm: (coreutils)comm invocation. Compare sorted files by line. * cp: (coreutils)cp invocation. Copy files. * csplit: (coreutils)csplit invocation. Split by context. * cut: (coreutils)cut invocation. Print selected parts of lines. * date: (coreutils)date invocation. Print/set system date and time. * dd: (coreutils)dd invocation. Copy and convert a file. * df: (coreutils)df invocation. Report file system disk usage. * diff: (diffutils)Invoking diff. Compare 2 files line by line. * diff3: (diffutils)Invoking diff3. Compare 3 files line by line. * dir: (coreutils)dir invocation. List directories briefly. * dircolors: (coreutils)dircolors invocation. Color setup for ls. * dirname: (coreutils)dirname invocation. Strip last file name component. * du: (coreutils)du invocation. Report on disk usage. * dvicopy: (web2c)dvicopy invocation. Virtual font expansion * dvitomp: (web2c)dvitomp invocation. DVI to MPX (MetaPost pictures). * dvitype: (web2c)dvitype invocation. DVI to human-readable text. * echo: (coreutils)echo invocation. Print a line of text. * env: (coreutils)env invocation. Modify the environment. * expand: (coreutils)expand invocation. Convert tabs to spaces. * expr: (coreutils)expr invocation. Evaluate expressions. * factor: (coreutils)factor invocation. Print prime factors * false: (coreutils)false invocation. Do nothing, unsuccessfully. * find: (find)Invoking find. Finding and acting on files. * fmt: (coreutils)fmt invocation. Reformat paragraph text. * fold: (coreutils)fold invocation. Wrap long input lines. * gftodvi: (web2c)gftodvi invocation. Generic font proofsheets. * gftopk: (web2c)gftopk invocation. Generic to packed fonts. * gftype: (web2c)gftype invocation. GF to human-readable text. * groups: (coreutils)groups invocation. Print group names a user is in. * gunzip: (gzip)Overview. Decompression. * gzexe: (gzip)Overview. Compress executables. * head: (coreutils)head invocation. Output the first part of files. * hostid: (coreutils)hostid invocation. Print numeric host identifier. * hostname: (coreutils)hostname invocation. Print or set system name. * id: (coreutils)id invocation. Print user identity. * install: (coreutils)install invocation. Copy files and set attributes. * join: (coreutils)join invocation. Join lines on a common field. * kill: (coreutils)kill invocation. Send a signal to processes. * link: (coreutils)link invocation. Make hard links between files. * ln: (coreutils)ln invocation. Make links between files. * locate: (find)Invoking locate. Finding files in a database. * logname: (coreutils)logname invocation. Print current login name. * ls: (coreutils)ls invocation. List directory contents. * md5sum: (coreutils)md5sum invocation. Print or check MD5 digests. * mf: (web2c)mf invocation. Creating typeface families. * mft: (web2c)mft invocation. Prettyprinting Metafont source. * mkdir: (coreutils)mkdir invocation. Create directories. * mkfifo: (coreutils)mkfifo invocation. Create FIFOs (named pipes). * mknod: (coreutils)mknod invocation. Create special files. * mktemp: (coreutils)mktemp invocation. Create temporary files. * mltex: (web2c)MLTeX. Multi-lingual TeX. * mpost: (web2c)mpost invocation. Creating technical diagrams. * mv: (coreutils)mv invocation. Rename files. * nice: (coreutils)nice invocation. Modify niceness. * nl: (coreutils)nl invocation. Number lines and write files. * nohup: (coreutils)nohup invocation. Immunize to hangups. * nproc: (coreutils)nproc invocation. Print the number of processors. * numfmt: (coreutils)numfmt invocation. Reformat numbers. * od: (coreutils)od invocation. Dump files in octal, etc. * paste: (coreutils)paste invocation. Merge lines of files. * patch: (diffutils)Invoking patch. Apply a patch to a file. * patgen: (web2c)patgen invocation. Creating hyphenation patterns. * pathchk: (coreutils)pathchk invocation. Check file name portability. * pktogf: (web2c)pktogf invocation. Packed to generic fonts. * pktype: (web2c)pktype invocation. PK to human-readable text. * pltotf: (web2c)pltotf invocation. Property list to TFM. * pooltype: (web2c)pooltype invocation. Display WEB pool files. * pr: (coreutils)pr invocation. Paginate or columnate files. * printenv: (coreutils)printenv invocation. Print environment variables. * printf: (coreutils)printf invocation. Format and print data. * ptx: (coreutils)ptx invocation. Produce permuted indexes. * pwd: (coreutils)pwd invocation. Print working directory. * readlink: (coreutils)readlink invocation. Print referent of a symlink. * realpath: (coreutils)realpath invocation. Print resolved file names. * rm: (coreutils)rm invocation. Remove files. * rmdir: (coreutils)rmdir invocation. Remove empty directories. * runcon: (coreutils)runcon invocation. Run in specified SELinux CTX. * sdiff: (diffutils)Invoking sdiff. Merge 2 files side-by-side. * seq: (coreutils)seq invocation. Print numeric sequences * sha1sum: (coreutils)sha1sum invocation. Print or check SHA-1 digests. * sha2: (coreutils)sha2 utilities. Print or check SHA-2 digests. * shred: (coreutils)shred invocation. Remove files more securely. * shuf: (coreutils)shuf invocation. Shuffling text files. * sleep: (coreutils)sleep invocation. Delay for a specified time. * sort: (coreutils)sort invocation. Sort text files. * split: (coreutils)split invocation. Split into pieces. * stat: (coreutils)stat invocation. Report file(system) status. * stdbuf: (coreutils)stdbuf invocation. Modify stdio buffering. * stty: (coreutils)stty invocation. Print/change terminal settings. * sum: (coreutils)sum invocation. Print traditional checksum. * sync: (coreutils)sync invocation. Synchronize memory to disk. * tac: (coreutils)tac invocation. Reverse files. * tail: (coreutils)tail invocation. Output the last part of files. * tangle: (web2c)tangle invocation. WEB to Pascal. * tee: (coreutils)tee invocation. Redirect to multiple files. * test: (coreutils)test invocation. File/string tests. * tex: (web2c)tex invocation. Typesetting. * tftopl: (web2c)tftopl invocation. TFM -> property list. * time: (time). Run programs and summarize system resource usage. * timeout: (coreutils)timeout invocation. Run with time limit. * touch: (coreutils)touch invocation. Change file timestamps. * tr: (coreutils)tr invocation. Translate characters. * true: (coreutils)true invocation. Do nothing, successfully. * truncate: (coreutils)truncate invocation. Shrink/extend size of a file. * tsort: (coreutils)tsort invocation. Topological sort. * tty: (coreutils)tty invocation. Print terminal name. * uname: (coreutils)uname invocation. Print system information. * unexpand: (coreutils)unexpand invocation. Convert spaces to tabs. * uniq: (coreutils)uniq invocation. Uniquify files. * unlink: (coreutils)unlink invocation. Removal via unlink(2). * updatedb: (find)Invoking updatedb. Building the locate database. * uptime: (coreutils)uptime invocation. Print uptime and load. * users: (coreutils)users invocation. Print current user names. * vdir: (coreutils)vdir invocation. List directories verbosely. * vftovp: (web2c)vftovp invocation. Virtual font -> virtual pl. * vptovf: (web2c)vptovf invocation. Virtual pl -> virtual font. * wc: (coreutils)wc invocation. Line, word, and byte counts. * weave: (web2c)weave invocation. WEB to TeX. * who: (coreutils)who invocation. Print who is logged in. * whoami: (coreutils)whoami invocation. Print effective user ID. * xargs: (find)Invoking xargs. Operating on many files. * yes: (coreutils)yes invocation. Print a string indefinitely. * zcat: (gzip)Overview. Decompression to stdout. * zdiff: (gzip)Overview. Compare compressed files. * zforce: (gzip)Overview. Force .gz extension on files. * zgrep: (gzip)Overview. Search compressed files. * zmore: (gzip)Overview. Decompression output by pages. Kernel * GRUB: (grub). The GRand Unified Bootloader * grub-dev: (grub-dev). The GRand Unified Bootloader Dev * grub-install: (grub)Invoking grub-install. Install GRUB on your drive * grub-mkconfig: (grub)Invoking grub-mkconfig. Generate GRUB configuration * grub-mkpasswd-pbkdf2: (grub)Invoking grub-mkpasswd-pbkdf2. * grub-mkrelpath: (grub)Invoking grub-mkrelpath. * grub-mkrescue: (grub)Invoking grub-mkrescue. Make a GRUB rescue image * grub-mount: (grub)Invoking grub-mount. Mount a file system using GRUB * grub-probe: (grub)Invoking grub-probe. Probe device information * grub-script-check: (grub)Invoking grub-script-check. Libraries * RLuserman: (rluserman). The GNU readline library User's Manual. Man-pages * Latex2man: (latex2man). Its Man-Page Math * bc: (bc). An arbitrary precision calculator language. * dc: (dc). Arbitrary precision RPN "Desktop Calculator". Network applications * Wget: (wget). Non-interactive network downloader. Programming * flex: (flex). Fast lexical analyzer generator (lex replacement). * gnucash: (gnucash-design). Design of the GnuCash program Programming Tools * Gperf: (gperf). Perfect Hash Function Generator. Software development * Autoconf Archive: (autoconf-archive). A collection of re-usable Autoconf macros. * Automake: (automake-1.15). Making GNU standards-compliant Makefiles. Sound * SSIP: (ssip). Speech Synthesis Interface Protocol. * Say for Speech Dispatcher: (spd-say). Say. * Speech Dispatcher: (speech-dispatcher). Speech Dispatcher. TeX * DVI-to-PNG: (dvipng). Translating TeX DVI files to Portable Network Graphics (PNG). * DVI-to-Postscript: (dvips). Translating TeX DVI files to PostScript. * Eplain: (eplain). Expanding on plain Tex. * EpsPDF: (epspdf). Portable GUI- and command-line EPS/PS/PDF conversion * Kpathsea: (kpathsea). File lookup along search paths. * LaTeX2e: (latex2e). Unofficial LaTeX reference manual. * LaTeX2e-es: (latex2e-es). Manual de extraoficial de LaTeX. * Naming TeX fonts: (fontname). Filenames for TeX fonts. * TL-build: (tlbuild). TeX Live configuration and development. * TeX Directories: (tds). A directory structure for TeX files. * TeXdraw: (texdraw). A system for producing PostScript drawings from TeX. * Web2c: (web2c). TeX, Metafont, and companion programs. * afm2tfm: (dvips)Invoking afm2tfm. Making Type 1 fonts available to TeX. * dvipng: (dvipng). A DVI-to-PNG translator. * dvips: (dvips)Invoking Dvips. DVI-to-PostScript translator. * kpsewhich: (kpathsea)Invoking kpsewhich. TeX file searching. * mf2pt1: (mf2pt1). PostScript Type 1 fonts from Metafont source. * mktexfmt: (kpathsea)mktex scripts. Format (fmt/base/mem) generation. * mktexlsr: (kpathsea)Filename database. Update ls-R. * mktexmf: (kpathsea)mktex scripts. MF source generation. * mktexpk: (kpathsea)mktex scripts. PK bitmap generation. * mktextex: (kpathsea)mktex scripts. TeX source generation. * mktextfm: (kpathsea)mktex scripts. TeX font metric generation. Text creation and manipulation * Diffutils: (diffutils). Comparing and merging files. * M4: (m4). A powerful macro processor. * grep: (grep). Print lines matching a pattern. * sed: (sed). Stream EDitor. command. Use * SSID MODE CHAN RATE SIGNAL BARS SECURITY to get current connections
6 years ago
Remove wifi info from File: dir, Node: Top, This is the top of the INFO tree. This is the Info main menu (aka directory node). A few useful Info commands: 'q' quits; '?' lists all Info commands; 'h' starts the Info tutorial; 'mTexinfo RET' visits the Texinfo manual, etc. * Menu: Basics * Common options: (coreutils)Common options. * Coreutils: (coreutils). Core GNU (file, text, shell) utilities. * Date input formats: (coreutils)Date input formats. * Ed: (ed). The GNU line editor * File permissions: (coreutils)File permissions. Access modes. * Finding files: (find). Operating on files matching certain criteria. C++ libraries * autosprintf: (autosprintf). Support for printf format strings in C++. Compression * Gzip: (gzip). General (de)compression of files (lzw). Development * SSIP: (ssip). Speech Synthesis Interface Protocol. * Speech Dispatcher: (speech-dispatcher). Speech Dispatcher. * libffi: (libffi). Portable foreign-function interface library. DOS * Mtools: (mtools). Mtools: utilities to access DOS disks in Unix. Editors * nano: (nano). Small and friendly text editor. General Commands * Screen: (screen). Full-screen window manager. GNU Gettext Utilities * autopoint: (gettext)autopoint Invocation. Copy gettext infrastructure. * envsubst: (gettext)envsubst Invocation. Expand environment variables. * gettextize: (gettext)gettextize Invocation. Prepare a package for gettext. * gettext: (gettext). GNU gettext utilities. * ISO3166: (gettext)Country Codes. ISO 3166 country codes. * ISO639: (gettext)Language Codes. ISO 639 language codes. * msgattrib: (gettext)msgattrib Invocation. Select part of a PO file. * msgcat: (gettext)msgcat Invocation. Combine several PO files. * msgcmp: (gettext)msgcmp Invocation. Compare a PO file and template. * msgcomm: (gettext)msgcomm Invocation. Match two PO files. * msgconv: (gettext)msgconv Invocation. Convert PO file to encoding. * msgen: (gettext)msgen Invocation. Create an English PO file. * msgexec: (gettext)msgexec Invocation. Process a PO file. * msgfilter: (gettext)msgfilter Invocation. Pipe a PO file through a filter. * msgfmt: (gettext)msgfmt Invocation. Make MO files out of PO files. * msggrep: (gettext)msggrep Invocation. Select part of a PO file. * msginit: (gettext)msginit Invocation. Create a fresh PO file. * msgmerge: (gettext)msgmerge Invocation. Update a PO file from template. * msgunfmt: (gettext)msgunfmt Invocation. Uncompile MO file into PO file. * msguniq: (gettext)msguniq Invocation. Unify duplicates for PO file. * ngettext: (gettext)ngettext Invocation. Translate a message with plural. * xgettext: (gettext)xgettext Invocation. Extract strings into a PO file. GNU organization * Maintaining Findutils: (find-maint). Maintaining GNU findutils GNU Utilities * dirmngr-client: (gnupg). X.509 CRL and OCSP client. * dirmngr: (gnupg). X.509 CRL and OCSP server. * gpg: (gnupg1). OpenPGP encryption and signing tool (v1). * gpg-agent: (gnupg). The secret key daemon. * gpg2: (gnupg). OpenPGP encryption and signing tool. * gpgsm: (gnupg). S/MIME encryption and signing tool. Individual utilities * aclocal-invocation: (automake-1.15)aclocal Invocation. Generating aclocal.m4. * arch: (coreutils)arch invocation. Print machine hardware name. * automake-invocation: (automake-1.15)automake Invocation. Generating Makefile.in. * base32: (coreutils)base32 invocation. Base32 encode/decode data. * base64: (coreutils)base64 invocation. Base64 encode/decode data. * basename: (coreutils)basename invocation. Strip directory and suffix. * bibtex: (web2c)bibtex invocation. Maintaining bibliographies. * cat: (coreutils)cat invocation. Concatenate and write files. * chcon: (coreutils)chcon invocation. Change SELinux CTX of files. * chgrp: (coreutils)chgrp invocation. Change file groups. * chmod: (coreutils)chmod invocation. Change access permissions. * chown: (coreutils)chown invocation. Change file owners and groups. * chroot: (coreutils)chroot invocation. Specify the root directory. * cksum: (coreutils)cksum invocation. Print POSIX CRC checksum. * cmp: (diffutils)Invoking cmp. Compare 2 files byte by byte. * comm: (coreutils)comm invocation. Compare sorted files by line. * cp: (coreutils)cp invocation. Copy files. * csplit: (coreutils)csplit invocation. Split by context. * cut: (coreutils)cut invocation. Print selected parts of lines. * date: (coreutils)date invocation. Print/set system date and time. * dd: (coreutils)dd invocation. Copy and convert a file. * df: (coreutils)df invocation. Report file system disk usage. * diff: (diffutils)Invoking diff. Compare 2 files line by line. * diff3: (diffutils)Invoking diff3. Compare 3 files line by line. * dir: (coreutils)dir invocation. List directories briefly. * dircolors: (coreutils)dircolors invocation. Color setup for ls. * dirname: (coreutils)dirname invocation. Strip last file name component. * du: (coreutils)du invocation. Report on disk usage. * dvicopy: (web2c)dvicopy invocation. Virtual font expansion * dvitomp: (web2c)dvitomp invocation. DVI to MPX (MetaPost pictures). * dvitype: (web2c)dvitype invocation. DVI to human-readable text. * echo: (coreutils)echo invocation. Print a line of text. * env: (coreutils)env invocation. Modify the environment. * expand: (coreutils)expand invocation. Convert tabs to spaces. * expr: (coreutils)expr invocation. Evaluate expressions. * factor: (coreutils)factor invocation. Print prime factors * false: (coreutils)false invocation. Do nothing, unsuccessfully. * find: (find)Invoking find. Finding and acting on files. * fmt: (coreutils)fmt invocation. Reformat paragraph text. * fold: (coreutils)fold invocation. Wrap long input lines. * gftodvi: (web2c)gftodvi invocation. Generic font proofsheets. * gftopk: (web2c)gftopk invocation. Generic to packed fonts. * gftype: (web2c)gftype invocation. GF to human-readable text. * groups: (coreutils)groups invocation. Print group names a user is in. * gunzip: (gzip)Overview. Decompression. * gzexe: (gzip)Overview. Compress executables. * head: (coreutils)head invocation. Output the first part of files. * hostid: (coreutils)hostid invocation. Print numeric host identifier. * hostname: (coreutils)hostname invocation. Print or set system name. * id: (coreutils)id invocation. Print user identity. * install: (coreutils)install invocation. Copy files and set attributes. * join: (coreutils)join invocation. Join lines on a common field. * kill: (coreutils)kill invocation. Send a signal to processes. * link: (coreutils)link invocation. Make hard links between files. * ln: (coreutils)ln invocation. Make links between files. * locate: (find)Invoking locate. Finding files in a database. * logname: (coreutils)logname invocation. Print current login name. * ls: (coreutils)ls invocation. List directory contents. * md5sum: (coreutils)md5sum invocation. Print or check MD5 digests. * mf: (web2c)mf invocation. Creating typeface families. * mft: (web2c)mft invocation. Prettyprinting Metafont source. * mkdir: (coreutils)mkdir invocation. Create directories. * mkfifo: (coreutils)mkfifo invocation. Create FIFOs (named pipes). * mknod: (coreutils)mknod invocation. Create special files. * mktemp: (coreutils)mktemp invocation. Create temporary files. * mltex: (web2c)MLTeX. Multi-lingual TeX. * mpost: (web2c)mpost invocation. Creating technical diagrams. * mv: (coreutils)mv invocation. Rename files. * nice: (coreutils)nice invocation. Modify niceness. * nl: (coreutils)nl invocation. Number lines and write files. * nohup: (coreutils)nohup invocation. Immunize to hangups. * nproc: (coreutils)nproc invocation. Print the number of processors. * numfmt: (coreutils)numfmt invocation. Reformat numbers. * od: (coreutils)od invocation. Dump files in octal, etc. * paste: (coreutils)paste invocation. Merge lines of files. * patch: (diffutils)Invoking patch. Apply a patch to a file. * patgen: (web2c)patgen invocation. Creating hyphenation patterns. * pathchk: (coreutils)pathchk invocation. Check file name portability. * pktogf: (web2c)pktogf invocation. Packed to generic fonts. * pktype: (web2c)pktype invocation. PK to human-readable text. * pltotf: (web2c)pltotf invocation. Property list to TFM. * pooltype: (web2c)pooltype invocation. Display WEB pool files. * pr: (coreutils)pr invocation. Paginate or columnate files. * printenv: (coreutils)printenv invocation. Print environment variables. * printf: (coreutils)printf invocation. Format and print data. * ptx: (coreutils)ptx invocation. Produce permuted indexes. * pwd: (coreutils)pwd invocation. Print working directory. * readlink: (coreutils)readlink invocation. Print referent of a symlink. * realpath: (coreutils)realpath invocation. Print resolved file names. * rm: (coreutils)rm invocation. Remove files. * rmdir: (coreutils)rmdir invocation. Remove empty directories. * runcon: (coreutils)runcon invocation. Run in specified SELinux CTX. * sdiff: (diffutils)Invoking sdiff. Merge 2 files side-by-side. * seq: (coreutils)seq invocation. Print numeric sequences * sha1sum: (coreutils)sha1sum invocation. Print or check SHA-1 digests. * sha2: (coreutils)sha2 utilities. Print or check SHA-2 digests. * shred: (coreutils)shred invocation. Remove files more securely. * shuf: (coreutils)shuf invocation. Shuffling text files. * sleep: (coreutils)sleep invocation. Delay for a specified time. * sort: (coreutils)sort invocation. Sort text files. * split: (coreutils)split invocation. Split into pieces. * stat: (coreutils)stat invocation. Report file(system) status. * stdbuf: (coreutils)stdbuf invocation. Modify stdio buffering. * stty: (coreutils)stty invocation. Print/change terminal settings. * sum: (coreutils)sum invocation. Print traditional checksum. * sync: (coreutils)sync invocation. Synchronize memory to disk. * tac: (coreutils)tac invocation. Reverse files. * tail: (coreutils)tail invocation. Output the last part of files. * tangle: (web2c)tangle invocation. WEB to Pascal. * tee: (coreutils)tee invocation. Redirect to multiple files. * test: (coreutils)test invocation. File/string tests. * tex: (web2c)tex invocation. Typesetting. * tftopl: (web2c)tftopl invocation. TFM -> property list. * time: (time). Run programs and summarize system resource usage. * timeout: (coreutils)timeout invocation. Run with time limit. * touch: (coreutils)touch invocation. Change file timestamps. * tr: (coreutils)tr invocation. Translate characters. * true: (coreutils)true invocation. Do nothing, successfully. * truncate: (coreutils)truncate invocation. Shrink/extend size of a file. * tsort: (coreutils)tsort invocation. Topological sort. * tty: (coreutils)tty invocation. Print terminal name. * uname: (coreutils)uname invocation. Print system information. * unexpand: (coreutils)unexpand invocation. Convert spaces to tabs. * uniq: (coreutils)uniq invocation. Uniquify files. * unlink: (coreutils)unlink invocation. Removal via unlink(2). * updatedb: (find)Invoking updatedb. Building the locate database. * uptime: (coreutils)uptime invocation. Print uptime and load. * users: (coreutils)users invocation. Print current user names. * vdir: (coreutils)vdir invocation. List directories verbosely. * vftovp: (web2c)vftovp invocation. Virtual font -> virtual pl. * vptovf: (web2c)vptovf invocation. Virtual pl -> virtual font. * wc: (coreutils)wc invocation. Line, word, and byte counts. * weave: (web2c)weave invocation. WEB to TeX. * who: (coreutils)who invocation. Print who is logged in. * whoami: (coreutils)whoami invocation. Print effective user ID. * xargs: (find)Invoking xargs. Operating on many files. * yes: (coreutils)yes invocation. Print a string indefinitely. * zcat: (gzip)Overview. Decompression to stdout. * zdiff: (gzip)Overview. Compare compressed files. * zforce: (gzip)Overview. Force .gz extension on files. * zgrep: (gzip)Overview. Search compressed files. * zmore: (gzip)Overview. Decompression output by pages. Kernel * GRUB: (grub). The GRand Unified Bootloader * grub-dev: (grub-dev). The GRand Unified Bootloader Dev * grub-install: (grub)Invoking grub-install. Install GRUB on your drive * grub-mkconfig: (grub)Invoking grub-mkconfig. Generate GRUB configuration * grub-mkpasswd-pbkdf2: (grub)Invoking grub-mkpasswd-pbkdf2. * grub-mkrelpath: (grub)Invoking grub-mkrelpath. * grub-mkrescue: (grub)Invoking grub-mkrescue. Make a GRUB rescue image * grub-mount: (grub)Invoking grub-mount. Mount a file system using GRUB * grub-probe: (grub)Invoking grub-probe. Probe device information * grub-script-check: (grub)Invoking grub-script-check. Libraries * RLuserman: (rluserman). The GNU readline library User's Manual. Man-pages * Latex2man: (latex2man). Its Man-Page Math * bc: (bc). An arbitrary precision calculator language. * dc: (dc). Arbitrary precision RPN "Desktop Calculator". Network applications * Wget: (wget). Non-interactive network downloader. Programming * flex: (flex). Fast lexical analyzer generator (lex replacement). * gnucash: (gnucash-design). Design of the GnuCash program Programming Tools * Gperf: (gperf). Perfect Hash Function Generator. Software development * Autoconf Archive: (autoconf-archive). A collection of re-usable Autoconf macros. * Automake: (automake-1.15). Making GNU standards-compliant Makefiles. Sound * SSIP: (ssip). Speech Synthesis Interface Protocol. * Say for Speech Dispatcher: (spd-say). Say. * Speech Dispatcher: (speech-dispatcher). Speech Dispatcher. TeX * DVI-to-PNG: (dvipng). Translating TeX DVI files to Portable Network Graphics (PNG). * DVI-to-Postscript: (dvips). Translating TeX DVI files to PostScript. * Eplain: (eplain). Expanding on plain Tex. * EpsPDF: (epspdf). Portable GUI- and command-line EPS/PS/PDF conversion * Kpathsea: (kpathsea). File lookup along search paths. * LaTeX2e: (latex2e). Unofficial LaTeX reference manual. * LaTeX2e-es: (latex2e-es). Manual de extraoficial de LaTeX. * Naming TeX fonts: (fontname). Filenames for TeX fonts. * TL-build: (tlbuild). TeX Live configuration and development. * TeX Directories: (tds). A directory structure for TeX files. * TeXdraw: (texdraw). A system for producing PostScript drawings from TeX. * Web2c: (web2c). TeX, Metafont, and companion programs. * afm2tfm: (dvips)Invoking afm2tfm. Making Type 1 fonts available to TeX. * dvipng: (dvipng). A DVI-to-PNG translator. * dvips: (dvips)Invoking Dvips. DVI-to-PostScript translator. * kpsewhich: (kpathsea)Invoking kpsewhich. TeX file searching. * mf2pt1: (mf2pt1). PostScript Type 1 fonts from Metafont source. * mktexfmt: (kpathsea)mktex scripts. Format (fmt/base/mem) generation. * mktexlsr: (kpathsea)Filename database. Update ls-R. * mktexmf: (kpathsea)mktex scripts. MF source generation. * mktexpk: (kpathsea)mktex scripts. PK bitmap generation. * mktextex: (kpathsea)mktex scripts. TeX source generation. * mktextfm: (kpathsea)mktex scripts. TeX font metric generation. Text creation and manipulation * Diffutils: (diffutils). Comparing and merging files. * M4: (m4). A powerful macro processor. * grep: (grep). Print lines matching a pattern. * sed: (sed). Stream EDitor. command. Use * SSID MODE CHAN RATE SIGNAL BARS SECURITY to get current connections
6 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
8 years ago
8 years ago
6 years ago
6 years ago
  1. /*
  2. WIFI MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include "wifi.h"
  6. #include "wifi_config.h"
  7. #include "telnet.h"
  8. #include "ws.h"
  9. bool _wifi_wps_running = false;
  10. bool _wifi_smartconfig_running = false;
  11. bool _wifi_smartconfig_initial = false;
  12. WiFiApMode _wifi_ap_mode = WiFiApMode::Fallback;
  13. #if WIFI_GRATUITOUS_ARP_SUPPORT
  14. unsigned long _wifi_gratuitous_arp_interval = 0;
  15. unsigned long _wifi_gratuitous_arp_last = 0;
  16. #endif
  17. // -----------------------------------------------------------------------------
  18. // PRIVATE
  19. // -----------------------------------------------------------------------------
  20. namespace settings {
  21. namespace internal {
  22. template <>
  23. WiFiApMode convert(const String& value) {
  24. switch (value.toInt()) {
  25. case 0:
  26. return WiFiApMode::Disabled;
  27. case 1:
  28. return WiFiApMode::Enabled;
  29. default:
  30. case 2:
  31. return WiFiApMode::Fallback;
  32. }
  33. }
  34. template<>
  35. WiFiSleepType_t convert(const String& value) {
  36. switch (value.toInt()) {
  37. case 2:
  38. return WIFI_MODEM_SLEEP;
  39. case 1:
  40. return WIFI_LIGHT_SLEEP;
  41. case 0:
  42. default:
  43. return WIFI_NONE_SLEEP;
  44. }
  45. }
  46. } // namespace internal
  47. } // namespace settings
  48. String _wifiSettingsSoftApSsid() {
  49. return getSetting("wifiApSsid", strlen(WIFI_AP_SSID)
  50. ? F(WIFI_AP_SSID)
  51. : getSetting("hostname", getIdentifier()));
  52. }
  53. String _wifiSettingsSoftApPass() {
  54. return getSetting("wifiApPass", strlen(WIFI_AP_PASS)
  55. ? F(WIFI_AP_PASS)
  56. : getAdminPass());
  57. }
  58. void _wifiUpdateSoftAP() {
  59. if (!WiFi.softAPgetStationNum()) {
  60. // Note: we know that c_str() will be copied, no need to persist it ourselves
  61. jw.setSoftAP(
  62. _wifiSettingsSoftApSsid().c_str(),
  63. #if USE_PASSWORD
  64. _wifiSettingsSoftApPass().c_str()
  65. #else
  66. nullptr
  67. #endif
  68. );
  69. }
  70. }
  71. void _wifiCheckAP() {
  72. if (
  73. (WiFiApMode::Fallback == _wifi_ap_mode)
  74. && ((WiFi.getMode() & WIFI_AP) > 0)
  75. && jw.connected()
  76. && (WiFi.softAPgetStationNum() == 0)
  77. ) {
  78. jw.enableAP(false);
  79. }
  80. }
  81. void _wifiConfigure() {
  82. jw.setHostname(getSetting("hostname", getIdentifier()).c_str());
  83. _wifiUpdateSoftAP();
  84. jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
  85. wifiReconnectCheck();
  86. _wifi_ap_mode = getSetting("wifiApMode", WIFI_AP_MODE);
  87. jw.enableAPFallback(_wifi_ap_mode != WiFiApMode::Disabled);
  88. jw.cleanNetworks();
  89. // If system is flagged unstable we do not init wifi networks
  90. #if SYSTEM_CHECK_ENABLED
  91. if (!systemCheck()) return;
  92. #endif
  93. unsigned char index = 0;
  94. for (index = 0; index < WIFI_MAX_NETWORKS; index++) {
  95. const auto ssid = getSetting({"ssid", index}, _wifiSSID(index));
  96. const auto pass = getSetting({"pass", index}, _wifiPass(index));
  97. if (!ssid.length()) {
  98. auto current = index;
  99. do {
  100. delSetting({"ssid", index});
  101. delSetting({"pass", index});
  102. delSetting({"ip", index});
  103. delSetting({"gw", index});
  104. delSetting({"mask", index});
  105. delSetting({"dns", index});
  106. } while (++index < WIFI_MAX_NETWORKS);
  107. index = current;
  108. break;
  109. }
  110. bool result = false;
  111. if (ssid.length() && pass.length()) {
  112. result = jw.addNetwork(
  113. ssid.c_str(),
  114. pass.c_str(),
  115. getSetting({"ip", index}, _wifiIP(index)).c_str(),
  116. getSetting({"gw", index}, _wifiGateway(index)).c_str(),
  117. getSetting({"mask", index}, _wifiNetmask(index)).c_str(),
  118. getSetting({"dns", index}, _wifiDNS(index)).c_str()
  119. );
  120. } else if (ssid.length()) {
  121. result = jw.addNetwork(ssid.c_str(), pass.c_str());
  122. }
  123. if (!result) break;
  124. }
  125. #if JUSTWIFI_ENABLE_SMARTCONFIG
  126. if (index == 0) _wifi_smartconfig_initial = true;
  127. #endif
  128. jw.enableScan(getSetting("wifiScan", 1 == WIFI_SCAN_NETWORKS));
  129. const auto sleep_mode = getSetting("wifiSleep", WIFI_SLEEP_MODE);
  130. WiFi.setSleepMode(sleep_mode);
  131. #if WIFI_GRATUITOUS_ARP_SUPPORT
  132. _wifi_gratuitous_arp_last = millis();
  133. _wifi_gratuitous_arp_interval = getSetting("wifiGarpIntvl", secureRandom(
  134. WIFI_GRATUITOUS_ARP_INTERVAL_MIN, WIFI_GRATUITOUS_ARP_INTERVAL_MAX
  135. ));
  136. #endif
  137. const auto tx_power = getSetting("wifiTxPwr", WIFI_OUTPUT_POWER_DBM);
  138. WiFi.setOutputPower(tx_power);
  139. }
  140. struct wifi_scan_info_t {
  141. String ssid_scan;
  142. int32_t rssi_scan;
  143. uint8_t sec_scan;
  144. uint8_t* BSSID_scan;
  145. int32_t chan_scan;
  146. bool hidden_scan;
  147. char buffer[128];
  148. };
  149. template <typename WiFiScanCallback>
  150. void _wifiScan(WiFiScanCallback callback) {
  151. DEBUG_MSG_P(PSTR("[WIFI] Start scanning\n"));
  152. auto networks = WiFi.scanNetworks();
  153. if (networks == WIFI_SCAN_FAILED) {
  154. DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n"));
  155. return;
  156. } else if (0 == networks) {
  157. DEBUG_MSG_P(PSTR("[WIFI] No networks found\n"));
  158. return;
  159. }
  160. DEBUG_MSG_P(PSTR("[WIFI] %d networks found:\n"), networks);
  161. // SDK pre-allocates a memory region with the scan data, but the only API to get them is through this 'getter' method.
  162. // Pick them one by one and pass into the callback as our custom struct.
  163. wifi_scan_info_t info;
  164. for (int i = 0; i < networks; ++i) {
  165. WiFi.getNetworkInfo(i,
  166. info.ssid_scan,
  167. info.sec_scan,
  168. info.rssi_scan,
  169. info.BSSID_scan,
  170. info.chan_scan,
  171. info.hidden_scan
  172. );
  173. snprintf_P(info.buffer, sizeof(info.buffer),
  174. PSTR("BSSID: %02X:%02X:%02X:%02X:%02X:%02X SEC: %s RSSI: %3d CH: %2d SSID: %s"),
  175. info.BSSID_scan[0], info.BSSID_scan[1], info.BSSID_scan[2], info.BSSID_scan[3], info.BSSID_scan[4], info.BSSID_scan[5],
  176. (info.sec_scan != ENC_TYPE_NONE ? "YES" : "NO "),
  177. info.rssi_scan,
  178. info.chan_scan,
  179. info.ssid_scan.c_str()
  180. );
  181. callback(info);
  182. }
  183. WiFi.scanDelete();
  184. }
  185. void _wifiCallback(justwifi_messages_t code, char * parameter) {
  186. if (MESSAGE_WPS_START == code) {
  187. _wifi_wps_running = true;
  188. return;
  189. }
  190. if (MESSAGE_SMARTCONFIG_START == code) {
  191. _wifi_smartconfig_running = true;
  192. return;
  193. }
  194. if (MESSAGE_WPS_ERROR == code || MESSAGE_SMARTCONFIG_ERROR == code) {
  195. _wifi_wps_running = false;
  196. _wifi_smartconfig_running = false;
  197. return;
  198. }
  199. if (MESSAGE_WPS_SUCCESS == code || MESSAGE_SMARTCONFIG_SUCCESS == code) {
  200. _wifi_wps_running = false;
  201. _wifi_smartconfig_running = false;
  202. const String current_ssid = WiFi.SSID();
  203. const String current_pass = WiFi.psk();
  204. // Write current ssid & pass at the end of the networks list
  205. unsigned char count;
  206. for (count = 0; count < WIFI_MAX_NETWORKS; count++) {
  207. const auto ssid = getSetting({"ssid", count}, _wifiSSID(count));
  208. const auto pass = getSetting({"pass", count}, _wifiPass(count));
  209. // Ignore existing network settings
  210. if (current_ssid.equals(ssid) && current_pass.equals(pass)) {
  211. return;
  212. }
  213. if (current_ssid.equals(ssid)) break;
  214. if (!ssid.length()) break;
  215. }
  216. // If we have reached the max we overwrite the first one
  217. if (WIFI_MAX_NETWORKS == count) count = 0;
  218. setSetting({"ssid", count}, current_ssid);
  219. setSetting({"pass", count}, current_pass);
  220. return;
  221. }
  222. }
  223. #if WIFI_AP_CAPTIVE
  224. #include "DNSServer.h"
  225. DNSServer _wifi_dnsServer;
  226. void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) {
  227. if (MESSAGE_ACCESSPOINT_CREATED == code) {
  228. _wifi_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
  229. _wifi_dnsServer.start(53, "*", WiFi.softAPIP());
  230. DEBUG_MSG_P(PSTR("[WIFI] Captive portal enabled\n"));
  231. }
  232. if (MESSAGE_CONNECTED == code) {
  233. _wifi_dnsServer.stop();
  234. DEBUG_MSG_P(PSTR("[WIFI] Captive portal disabled\n"));
  235. }
  236. }
  237. #endif // WIFI_AP_CAPTIVE
  238. #if DEBUG_SUPPORT
  239. void _wifiDebugCallback(justwifi_messages_t code, char * parameter) {
  240. // -------------------------------------------------------------------------
  241. if (code == MESSAGE_SCANNING) {
  242. DEBUG_MSG_P(PSTR("[WIFI] Scanning\n"));
  243. }
  244. if (code == MESSAGE_SCAN_FAILED) {
  245. DEBUG_MSG_P(PSTR("[WIFI] Scan failed\n"));
  246. }
  247. if (code == MESSAGE_NO_NETWORKS) {
  248. DEBUG_MSG_P(PSTR("[WIFI] No networks found\n"));
  249. }
  250. if (code == MESSAGE_NO_KNOWN_NETWORKS) {
  251. DEBUG_MSG_P(PSTR("[WIFI] No known networks found\n"));
  252. }
  253. if (code == MESSAGE_FOUND_NETWORK) {
  254. DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter);
  255. }
  256. // -------------------------------------------------------------------------
  257. if (code == MESSAGE_CONNECTING) {
  258. DEBUG_MSG_P(PSTR("[WIFI] Connecting to %s\n"), parameter);
  259. }
  260. if (code == MESSAGE_CONNECT_WAITING) {
  261. // too much noise
  262. }
  263. if (code == MESSAGE_CONNECT_FAILED) {
  264. DEBUG_MSG_P(PSTR("[WIFI] Could not connect to %s\n"), parameter);
  265. }
  266. if (code == MESSAGE_CONNECTED) {
  267. wifiDebug(WIFI_STA);
  268. }
  269. if (code == MESSAGE_DISCONNECTED) {
  270. DEBUG_MSG_P(PSTR("[WIFI] Disconnected\n"));
  271. }
  272. // -------------------------------------------------------------------------
  273. if (code == MESSAGE_ACCESSPOINT_CREATING) {
  274. DEBUG_MSG_P(PSTR("[WIFI] Creating access point\n"));
  275. }
  276. if (code == MESSAGE_ACCESSPOINT_CREATED) {
  277. wifiDebug(WIFI_AP);
  278. }
  279. if (code == MESSAGE_ACCESSPOINT_FAILED) {
  280. DEBUG_MSG_P(PSTR("[WIFI] Could not create access point\n"));
  281. }
  282. if (code == MESSAGE_ACCESSPOINT_DESTROYED) {
  283. _wifiUpdateSoftAP();
  284. DEBUG_MSG_P(PSTR("[WIFI] Access point destroyed\n"));
  285. }
  286. // -------------------------------------------------------------------------
  287. if (code == MESSAGE_WPS_START) {
  288. DEBUG_MSG_P(PSTR("[WIFI] WPS started\n"));
  289. }
  290. if (code == MESSAGE_WPS_SUCCESS) {
  291. DEBUG_MSG_P(PSTR("[WIFI] WPS succeded!\n"));
  292. }
  293. if (code == MESSAGE_WPS_ERROR) {
  294. DEBUG_MSG_P(PSTR("[WIFI] WPS failed\n"));
  295. }
  296. // ------------------------------------------------------------------------
  297. if (code == MESSAGE_SMARTCONFIG_START) {
  298. DEBUG_MSG_P(PSTR("[WIFI] Smart Config started\n"));
  299. }
  300. if (code == MESSAGE_SMARTCONFIG_SUCCESS) {
  301. DEBUG_MSG_P(PSTR("[WIFI] Smart Config succeded!\n"));
  302. }
  303. if (code == MESSAGE_SMARTCONFIG_ERROR) {
  304. DEBUG_MSG_P(PSTR("[WIFI] Smart Config failed\n"));
  305. }
  306. }
  307. #endif // DEBUG_SUPPORT
  308. // -----------------------------------------------------------------------------
  309. // SETTINGS
  310. // -----------------------------------------------------------------------------
  311. #if TERMINAL_SUPPORT
  312. void _wifiInitCommands() {
  313. terminalRegisterCommand(F("WIFI.STATIONS"), [](const terminal::CommandContext& ctx) {
  314. char buffer[64];
  315. size_t stations = 0;
  316. auto* station = wifi_softap_get_station_info();
  317. while (station) {
  318. sprintf_P(buffer,
  319. PSTR("[WIFI] %02X:%02X:%02X:%02X:%02X:%02X %s"),
  320. MAC2STR(station->bssid),
  321. IPAddress(station->ip.addr).toString().c_str()
  322. );
  323. ctx.output.println(buffer);
  324. station = STAILQ_NEXT(station, next);
  325. ++stations;
  326. }
  327. wifi_softap_free_station_info();
  328. if (!stations) {
  329. terminalError(ctx, F("No stations connected"));
  330. return;
  331. }
  332. terminalOK(ctx);
  333. });
  334. terminalRegisterCommand(F("WIFI"), [](const terminal::CommandContext&) {
  335. wifiDebug();
  336. terminalOK();
  337. });
  338. terminalRegisterCommand(F("WIFI.RESET"), [](const terminal::CommandContext&) {
  339. _wifiConfigure();
  340. wifiDisconnect();
  341. terminalOK();
  342. });
  343. terminalRegisterCommand(F("WIFI.STA"), [](const terminal::CommandContext&) {
  344. wifiStartSTA();
  345. terminalOK();
  346. });
  347. terminalRegisterCommand(F("WIFI.AP"), [](const terminal::CommandContext&) {
  348. wifiStartAP();
  349. terminalOK();
  350. });
  351. #if defined(JUSTWIFI_ENABLE_WPS)
  352. terminalRegisterCommand(F("WIFI.WPS"), [](const terminal::CommandContext&) {
  353. wifiStartWPS();
  354. terminalOK();
  355. });
  356. #endif // defined(JUSTWIFI_ENABLE_WPS)
  357. #if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  358. terminalRegisterCommand(F("WIFI.SMARTCONFIG"), [](const terminal::CommandContext&) {
  359. wifiStartSmartConfig();
  360. terminalOK();
  361. });
  362. #endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  363. terminalRegisterCommand(F("WIFI.SCAN"), [](const terminal::CommandContext&) {
  364. _wifiScan([](wifi_scan_info_t& info) {
  365. DEBUG_MSG_P(PSTR("[WIFI] > %s\n"), info.buffer);
  366. });
  367. terminalOK();
  368. });
  369. }
  370. #endif
  371. // -----------------------------------------------------------------------------
  372. // WEB
  373. // -----------------------------------------------------------------------------
  374. #if WEB_SUPPORT
  375. bool _wifiWebSocketOnKeyCheck(const char * key, JsonVariant& value) {
  376. if (strncmp(key, "wifi", 4) == 0) return true;
  377. if (strncmp(key, "ssid", 4) == 0) return true;
  378. if (strncmp(key, "pass", 4) == 0) return true;
  379. if (strncmp(key, "ip", 2) == 0) return true;
  380. if (strncmp(key, "gw", 2) == 0) return true;
  381. if (strncmp(key, "mask", 4) == 0) return true;
  382. if (strncmp(key, "dns", 3) == 0) return true;
  383. return false;
  384. }
  385. void _wifiWebSocketOnConnected(JsonObject& root) {
  386. root["wifiScan"] = getSetting("wifiScan", 1 == WIFI_SCAN_NETWORKS);
  387. JsonObject& wifi = root.createNestedObject("wifi");
  388. root["max"] = WIFI_MAX_NETWORKS;
  389. const char* keys[] = {
  390. "ssid", "pass", "ip", "gw", "mask", "dns", "stored"
  391. };
  392. JsonArray& schema = wifi.createNestedArray("schema");
  393. schema.copyFrom(keys, 7);
  394. JsonArray& networks = wifi.createNestedArray("networks");
  395. for (unsigned char index = 0; index < WIFI_MAX_NETWORKS; ++index) {
  396. if (!getSetting({"ssid", index}, _wifiSSID(index)).length()) break;
  397. JsonArray& network = networks.createNestedArray();
  398. network.add(getSetting({"ssid", index}, _wifiSSID(index)));
  399. network.add(getSetting({"pass", index}, _wifiPass(index)));
  400. network.add(getSetting({"ip", index}, _wifiIP(index)));
  401. network.add(getSetting({"gw", index}, _wifiGateway(index)));
  402. network.add(getSetting({"mask", index}, _wifiNetmask(index)));
  403. network.add(getSetting({"dns", index}, _wifiDNS(index)));
  404. network.add(_wifiHasSSID(index));
  405. }
  406. }
  407. void _wifiWebSocketScan(JsonObject& root) {
  408. JsonArray& scanResult = root.createNestedArray("scanResult");
  409. _wifiScan([&scanResult](wifi_scan_info_t& info) {
  410. scanResult.add(info.buffer);
  411. });
  412. }
  413. void _wifiWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) {
  414. if (strcmp(action, "scan") == 0) wsPost(client_id, _wifiWebSocketScan);
  415. }
  416. #endif
  417. // -----------------------------------------------------------------------------
  418. // SUPPORT
  419. // -----------------------------------------------------------------------------
  420. #if WIFI_GRATUITOUS_ARP_SUPPORT
  421. // ref: lwip src/core/netif.c netif_issue_reports(...)
  422. // ref: esp-lwip/core/ipv4/etharp.c garp_tmr()
  423. // TODO: only for ipv4, need (?) a different method with ipv6
  424. bool _wifiSendGratuitousArp() {
  425. bool result = false;
  426. for (netif* interface = netif_list; interface != nullptr; interface = interface->next) {
  427. if (
  428. (interface->flags & NETIF_FLAG_ETHARP)
  429. && (interface->hwaddr_len == ETHARP_HWADDR_LEN)
  430. #if LWIP_VERSION_MAJOR == 1
  431. && (!ip_addr_isany(&interface->ip_addr))
  432. #else
  433. && (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
  434. #endif
  435. && (interface->flags & NETIF_FLAG_LINK_UP)
  436. && (interface->flags & NETIF_FLAG_UP)
  437. ) {
  438. etharp_gratuitous(interface);
  439. result = true;
  440. }
  441. }
  442. return result;
  443. }
  444. void _wifiSendGratuitousArp(unsigned long interval) {
  445. if (millis() - _wifi_gratuitous_arp_last > interval) {
  446. _wifi_gratuitous_arp_last = millis();
  447. _wifiSendGratuitousArp();
  448. }
  449. }
  450. #endif // WIFI_GRATUITOUS_ARP_SUPPORT
  451. // -----------------------------------------------------------------------------
  452. // INFO
  453. // -----------------------------------------------------------------------------
  454. // backported WiFiAPClass methods
  455. String _wifiRuntimeSoftApSsid() {
  456. struct softap_config config;
  457. wifi_softap_get_config(&config);
  458. char* name = reinterpret_cast<char*>(config.ssid);
  459. char ssid[sizeof(config.ssid) + 1];
  460. memcpy(ssid, name, sizeof(config.ssid));
  461. ssid[sizeof(config.ssid)] = '\0';
  462. return String(ssid);
  463. }
  464. String _wifiRuntimeSoftApPass() {
  465. struct softap_config config;
  466. wifi_softap_get_config(&config);
  467. char* pass = reinterpret_cast<char*>(config.password);
  468. char psk[sizeof(config.password) + 1];
  469. memcpy(psk, pass, sizeof(config.password));
  470. psk[sizeof(config.password)] = '\0';
  471. return String(psk);
  472. }
  473. void wifiDebug(WiFiMode_t modes) {
  474. #if DEBUG_SUPPORT
  475. bool footer = false;
  476. if (((modes & WIFI_STA) > 0) && ((WiFi.getMode() & WIFI_STA) > 0)) {
  477. DEBUG_MSG_P(PSTR("[WIFI] ------------------------------------- MODE STA\n"));
  478. DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), WiFi.SSID().c_str());
  479. DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.localIP().toString().c_str());
  480. DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.macAddress().c_str());
  481. DEBUG_MSG_P(PSTR("[WIFI] GW %s\n"), WiFi.gatewayIP().toString().c_str());
  482. DEBUG_MSG_P(PSTR("[WIFI] DNS %s\n"), WiFi.dnsIP().toString().c_str());
  483. DEBUG_MSG_P(PSTR("[WIFI] MASK %s\n"), WiFi.subnetMask().toString().c_str());
  484. DEBUG_MSG_P(PSTR("[WIFI] HOST http://%s.local\n"), WiFi.hostname().c_str());
  485. DEBUG_MSG_P(PSTR("[WIFI] BSSID %s\n"), WiFi.BSSIDstr().c_str());
  486. DEBUG_MSG_P(PSTR("[WIFI] CH %d\n"), WiFi.channel());
  487. DEBUG_MSG_P(PSTR("[WIFI] RSSI %d\n"), WiFi.RSSI());
  488. footer = true;
  489. }
  490. if (((modes & WIFI_AP) > 0) && ((WiFi.getMode() & WIFI_AP) > 0)) {
  491. DEBUG_MSG_P(PSTR("[WIFI] -------------------------------------- MODE AP\n"));
  492. DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), _wifiRuntimeSoftApSsid().c_str());
  493. DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), _wifiRuntimeSoftApPass().c_str());
  494. DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str());
  495. DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str());
  496. footer = true;
  497. }
  498. if (WiFi.getMode() == 0) {
  499. DEBUG_MSG_P(PSTR("[WIFI] ------------------------------------- MODE OFF\n"));
  500. DEBUG_MSG_P(PSTR("[WIFI] No connection\n"));
  501. footer = true;
  502. }
  503. if (footer) {
  504. DEBUG_MSG_P(PSTR("[WIFI] ----------------------------------------------\n"));
  505. }
  506. #endif //DEBUG_SUPPORT
  507. }
  508. void wifiDebug() {
  509. wifiDebug(WIFI_AP_STA);
  510. }
  511. // -----------------------------------------------------------------------------
  512. // API
  513. // -----------------------------------------------------------------------------
  514. String getIP() {
  515. if (WiFi.getMode() == WIFI_AP) {
  516. return WiFi.softAPIP().toString();
  517. }
  518. return WiFi.localIP().toString();
  519. }
  520. String getNetwork() {
  521. if (WiFi.getMode() == WIFI_AP) {
  522. return jw.getAPSSID();
  523. }
  524. return WiFi.SSID();
  525. }
  526. bool wifiConnected() {
  527. return jw.connected();
  528. }
  529. void wifiDisconnect() {
  530. jw.disconnect();
  531. }
  532. void wifiStartSTA() {
  533. jw.disconnect();
  534. jw.enableSTA(true);
  535. jw.enableAP(false);
  536. }
  537. void wifiStartAP(bool only) {
  538. if (only) {
  539. jw.enableSTA(false);
  540. jw.disconnect();
  541. jw.resetReconnectTimeout();
  542. }
  543. jw.enableAP(true);
  544. }
  545. void wifiStartAP() {
  546. wifiStartAP(true);
  547. }
  548. #if defined(JUSTWIFI_ENABLE_WPS)
  549. void wifiStartWPS() {
  550. jw.enableAP(false);
  551. jw.disconnect();
  552. jw.startWPS();
  553. }
  554. #endif // defined(JUSTWIFI_ENABLE_WPS)
  555. #if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  556. void wifiStartSmartConfig() {
  557. jw.enableAP(false);
  558. jw.disconnect();
  559. jw.startSmartConfig();
  560. }
  561. #endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
  562. void wifiReconnectCheck() {
  563. bool connected = false;
  564. #if WEB_SUPPORT
  565. if (wsConnected()) connected = true;
  566. #endif
  567. #if TELNET_SUPPORT
  568. if (telnetConnected()) connected = true;
  569. #endif
  570. jw.enableSTA(true);
  571. jw.setReconnectTimeout(connected ? 0 : WIFI_RECONNECT_INTERVAL);
  572. }
  573. uint8_t wifiState() {
  574. uint8_t state = 0;
  575. if (jw.connected()) state += WIFI_STATE_STA;
  576. if (jw.connectable()) state += WIFI_STATE_AP;
  577. if (_wifi_wps_running) state += WIFI_STATE_WPS;
  578. if (_wifi_smartconfig_running) state += WIFI_STATE_SMARTCONFIG;
  579. return state;
  580. }
  581. void wifiRegister(wifi_callback_f callback) {
  582. jw.subscribe(callback);
  583. }
  584. WiFiApMode wifiApMode() {
  585. return _wifi_ap_mode;
  586. }
  587. // -----------------------------------------------------------------------------
  588. // INITIALIZATION
  589. // -----------------------------------------------------------------------------
  590. void wifiSetup() {
  591. // Backwards compat, we need to specify namespace
  592. moveSetting("apmode", "wifiApMode");
  593. _wifiConfigure();
  594. // Note that maximum amount of stations is set by `WiFi.softAP(...)` call, but justwifi handles that.
  595. // Default is 4, which we use here. However, maximum is 8. ref:
  596. // https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html#softap
  597. #if WIFI_AP_LEASES_SUPPORT
  598. wifiRegister([](justwifi_messages_t code, char*) {
  599. if (MESSAGE_ACCESSPOINT_CREATING != code) return;
  600. for (unsigned char index = 0; index < 4; ++index) {
  601. auto lease = getSetting({"wifiApLease", index});
  602. if (12 != lease.length()) {
  603. break;
  604. }
  605. uint8_t mac[6] = {0};
  606. if (!hexDecode(lease.c_str(), lease.length(), mac, sizeof(mac))) {
  607. break;
  608. }
  609. wifi_softap_add_dhcps_lease(mac);
  610. }
  611. });
  612. #endif
  613. if (WiFiApMode::Enabled ==_wifi_ap_mode) {
  614. jw.enableAP(true);
  615. jw.enableSTA(true);
  616. }
  617. #if JUSTWIFI_ENABLE_SMARTCONFIG
  618. if (_wifi_smartconfig_initial) jw.startSmartConfig();
  619. #endif
  620. // Message callbacks
  621. wifiRegister(_wifiCallback);
  622. #if WIFI_AP_CAPTIVE
  623. wifiRegister(_wifiCaptivePortal);
  624. #endif
  625. #if DEBUG_SUPPORT
  626. wifiRegister(_wifiDebugCallback);
  627. #endif
  628. #if WEB_SUPPORT
  629. wsRegister()
  630. .onAction(_wifiWebSocketOnAction)
  631. .onConnected(_wifiWebSocketOnConnected)
  632. .onKeyCheck(_wifiWebSocketOnKeyCheck);
  633. #endif
  634. #if TERMINAL_SUPPORT
  635. _wifiInitCommands();
  636. #endif
  637. // Main callbacks
  638. espurnaRegisterLoop(wifiLoop);
  639. espurnaRegisterReload(_wifiConfigure);
  640. }
  641. void wifiLoop() {
  642. // Main wifi loop
  643. jw.loop();
  644. // Process captrive portal DNS queries if in AP mode only
  645. #if WIFI_AP_CAPTIVE
  646. if ((WiFi.getMode() & WIFI_AP) == WIFI_AP) {
  647. _wifi_dnsServer.processNextRequest();
  648. }
  649. #endif
  650. // Only send out gra arp when in STA mode
  651. #if WIFI_GRATUITOUS_ARP_SUPPORT
  652. if (_wifi_gratuitous_arp_interval) {
  653. _wifiSendGratuitousArp(_wifi_gratuitous_arp_interval);
  654. }
  655. #endif
  656. // Check if we should disable AP
  657. static unsigned long last = 0;
  658. if (millis() - last > 60000) {
  659. last = millis();
  660. _wifiCheckAP();
  661. }
  662. }