summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Zhineng <[email protected]>2025-07-02 21:29:40 +0800
committerGitHub <[email protected]>2025-07-02 21:29:40 +0800
commit72e1c3cb3430a19cc4d5b1d1f57bc40be8d10036 (patch)
treee98b6314e0c82de97348601bf571b832a253f934
parentfd5876743c2070a5259c36110e7e02f80ed80458 (diff)
parent72643a9424fc8e71d0360d710581c194fe6ba945 (diff)
downloadserver-main.tar.gz
server-main.zip
Merge pull request #3 from openairmx/eagle-onlineHEADmain
Eagle online controller
-rw-r--r--README.md13
-rw-r--r--server.mjs14
-rw-r--r--server.test.mjs16
3 files changed, 42 insertions, 1 deletions
diff --git a/README.md b/README.md
index 86994e5..e042ce3 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ HOSTNAME="127.0.0.1" PORT=8080 node server.mjs
seconds back to the device.
</dd>
- <dt>GET /eagle</dt>
+ <dt>GET /eagle?path=eagle/GET/genId</dt>
<dd>
During the pairing process, when the device receives the Wi-Fi credentials
you provide, it registers itself with this endpoint along with its MAC
@@ -49,6 +49,17 @@ HOSTNAME="127.0.0.1" PORT=8080 node server.mjs
the final stage of the pairing process.
</dd>
+ <dt>GET /eagle?path=eagle/GET/online</dt>
+ <dd>
+ <p>The device will access this endpoint immediately after it receives the
+ Wi-Fi credentials during the pairing process. Based on the hints from
+ the path name and payload, we believe this endpoint allows the device to
+ determine if it has successfully connected to the AIRMX network.</p>
+ <p>Therefore, regardless of the parameters the API receives, we will
+ always provide it with a predetermined response, making it appear as
+ though the air monitor and the AIRMX Pro unit are already connected.</p>
+ </dd>
+
<dt>GET /exchange</dt>
<dd>
To streamline device pairing, we introduce an unofficial API that enables
diff --git a/server.mjs b/server.mjs
index 2475442..b431d1e 100644
--- a/server.mjs
+++ b/server.mjs
@@ -35,6 +35,9 @@ const eagleController = (req, res) => {
case 'eagle/GET/genId':
eagleGenIdController(req, res)
break
+ case 'eagle/GET/online':
+ eagleOnlineController(req, res)
+ break
default:
notFoundController(req, res)
break
@@ -66,6 +69,17 @@ const eagleGenIdController = (req, res) => {
}))
}
+const eagleOnlineController = (req, res) => {
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({
+ status: 200,
+ data: {
+ snow: 1, // Air quality monitor
+ eagle: 1 // The AIRMX Pro unit
+ }
+ }))
+}
+
const exchangeController = (req, res) => {
const [, query] = req.url.split('?')
const params = new URLSearchParams(query)
diff --git a/server.test.mjs b/server.test.mjs
index 1e44083..24437b6 100644
--- a/server.test.mjs
+++ b/server.test.mjs
@@ -142,6 +142,22 @@ test('device registration endpoint returns not found if path is not supported',
assert.strictEqual(res.status, 404)
})
+test('device status endpoint', async () => {
+ const params = new URLSearchParams({
+ source: 5,
+ reqid: '0000000000',
+ eagleId: 1,
+ path: 'eagle/GET/online',
+ params: '{}',
+ sig: '00000000000000000000000000000000'
+ })
+ const res = await fetch(`${baseUrl}/eagle?${params.toString()}`)
+ assert.strictEqual(res.status, 200)
+ const data = await res.json()
+ assert.strictEqual(data.data.snow, 1)
+ assert.strictEqual(data.data.eagle, 1)
+})
+
test('exchange endpoint', async () => {
const stubMacAddress = '0000000000'
const stubKey = '00000000000000000000000000000000'