-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 387d43b
Showing
12 changed files
with
2,695 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20] | ||
pnpm-version: [9] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
version: ${{ matrix.pnpm-version }} | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run CI | ||
run: npm run ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Node.js | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# TypeScript | ||
*.tsbuildinfo | ||
|
||
# Logs | ||
logs | ||
*.log | ||
logs/*.log | ||
|
||
# Dependency directories | ||
jspm_packages/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output directories | ||
dist/ | ||
build/ | ||
out/ | ||
|
||
# IDEs and editors | ||
.vscode/ | ||
.idea/ | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# Environment variables | ||
.env | ||
.env.test | ||
|
||
# macOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
!dist | ||
src | ||
.changeset | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Embedded : WiFi connection manager | ||
|
||
> [!IMPORTANT] | ||
> This module is ESM only. | ||
A robust solution to manage Wi-Fi connections in embedded systems using the Moddable SDK. `WiFiConnectionManager` simplifies the process of maintaining an active connection to a Wi-Fi access point. | ||
|
||
## Features | ||
|
||
- **Auto-reconnect:** Automatically retries connection if unavailable at startup or dropped during runtime. | ||
- **Connection lifecycle management:** Allows clean disconnection using `close`. | ||
- **Redundant message suppression:** Filters out repetitive `WiFi.disconnect` messages. | ||
- **Convenient readiness check:** Use the `ready` getter to quickly determine if Wi-Fi is connected. | ||
- **Connection timeout handling:** Forces a disconnect and retries if no IP address is assigned within a configurable timeout. | ||
- **Graceful recovery:** Waits a configurable duration after an unforced disconnect for a clean reconnect. | ||
- **Multiple access points:** Attempts connection to access points in order from a provided list. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install @embedded-js/wifi-connection-manager | ||
``` | ||
|
||
```ts | ||
import Net from "net"; // From moddable SDK | ||
import { WiFiConnectionManager } from "@embedded-js/wifi-connection-manager"; | ||
|
||
const manager = new WiFiConnectionManager( | ||
[ | ||
// First access point to attempt | ||
{ | ||
ssid: "Freebox-ScreamZ", | ||
password: "invalid!", // Invalid password for testing in a simulator | ||
}, | ||
// Second access point to attempt | ||
{ | ||
ssid: "Freebox-ScreamZ", | ||
password: "good_password", | ||
}, | ||
], | ||
(message) => { | ||
switch (msg) { | ||
case WiFiConnectionManager.gotIP.connected: | ||
break; // still waiting for IP address | ||
case WiFiConnectionManager.gotIP.gotIP: | ||
trace(`IP address ${Net.get("IP")}\n`); | ||
break; | ||
case WiFiConnectionManager.gotIP.disconnected: | ||
break; // connection lost | ||
} | ||
} | ||
); | ||
|
||
// Example: Checking if connected (procedural way) | ||
if (manager.ready) { | ||
console.log("Wi-Fi is connected!"); | ||
} | ||
|
||
// Close connection when needed | ||
manager.close(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", | ||
"vcs": { | ||
"enabled": false, | ||
"clientKind": "git", | ||
"useIgnoreFile": false | ||
}, | ||
"files": { | ||
"ignoreUnknown": false, | ||
"ignore": ["dist"] | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "tab" | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "double" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@embedded-js/wifi-connection-manager", | ||
"description": "A wifi connection manager for Embedded JS that supports multiple networks and auto-reconnect.", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsup", | ||
"ci": "tsc && pnpm run build && biome check && pnpm run check-exports", | ||
"format": "biome check --write", | ||
"check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm", | ||
"prepublishOnly": "pnpm run ci" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "^0.17.0", | ||
"@biomejs/biome": "1.9.4", | ||
"@changesets/cli": "^2.27.9", | ||
"@moddable/typings": "^5.2.0", | ||
"tsup": "^8.3.5", | ||
"type-fest": "^4.27.0", | ||
"typescript": "^5.6.3" | ||
} | ||
} |
Oops, something went wrong.