npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

metermatesdk

v1.0.5

Published

SDK for communicating with the MeterMate P1 WiFi dongle

Downloads

441

Readme

MeterMate SDK

npm

Official SDK for communicating with the MeterMate WiFi P1 dongle over TCP.


Overview

metermate-sdk provides a clean, high-level JavaScript API for provisioning and communicating with the MeterMate WiFi P1 dongle.

It abstracts:

  • TCP socket communication
  • JSON protocol encoding/decoding
  • Transport differences (React Native vs Mock)
  • Command number mapping
  • Basic connection lifecycle

The SDK exposes a single public class:

import { DongleClient } from "metermatesdk";

Architecture

High-Level Design

The SDK consists of:

  • DongleClient (public API facade)
  • Transport layer (pluggable runtime-specific IO)
  • Protocol helpers (JSON encoding/decoding)
  • Command constants (numeric mapping)
Application
     │
     ▼
DongleClient (public API)
     │
     ▼
Transport (react-native | mock | node*)
     │
     ▼
TCP Socket
     │
     ▼
MeterMate Dongle (JSON protocol)

Public API Layer

DongleClient:

  • Owns host and port (default: 10.0.0.1:9999)
  • Delegates IO to a selected transport
  • Exposes high-level provisioning methods

Transport Layer

Supported modes:

  • "react-native" — real TCP via react-native-tcp-socket
  • "mock" — simulated dongle for tests
  • "node" — reserved for future Node TCP support

Transports implement:

connect(host, port)
sendCommand(commandId, params)
close()

Protocol

The dongle protocol is JSON-based.

Each request is sent as:

{
  "msgType": <commandId>,
  ...params
}

Responses are expected to be JSON objects.


Installation

React Native

npm install metermatesdk react-native-tcp-socket react-native-wifi-reborn

You must use a dev-client or bare workflow. Expo Go does NOT support raw TCP sockets.

Node (Mock Testing Only)

npm install metermatesdk

Usage

React Native Example

import { DongleClient } from "metermatesdk";

const client = await DongleClient.create("react-native");

await client.connect();

const wifiList = await client.getWifiList();

await client.selectWifiNetwork("MySSID", "password123");

const internetOk = await client.checkInternet();

console.log("Internet OK?", internetOk);

client.close();

Mock Mode Example (Testing)

import { DongleClient } from "metermatesdk";

const client = await DongleClient.create("mock");

await client.connect();

const wifiList = await client.getWifiList();
console.log(wifiList.APList);

await client.selectWifiNetwork("TestSSID", "TestPw");

const ok = await client.checkInternet();
console.log(ok);

client.close();

API Reference

DongleClient.create(mode, host?, port?)

Creates a client using the selected transport.

| Mode | Description | |------|-------------| | "react-native" | Real TCP transport | | "mock" | Simulated transport | | "node" | Reserved for future Node TCP transport |

Optional:

  • host (default 10.0.0.1)
  • port (default 9999)

client.connect()

Establishes a TCP connection to the dongle.

Must be called before sending commands.

Throws if connection fails.


client.getWifiList()

Scans for available WiFi networks.

Returns

{
  APList: [
    {
      ssid: string,
      rssi: number,
      security: number
    }
  ]
}

client.selectWifiNetwork(ssid, password, isHidden?, securityType?)

Sends WiFi credentials to the dongle.

Parameters:

  • ssid: string
  • password: string
  • isHidden: boolean (default false)
  • securityType: number (default 3)

Returns

{
  ok?: boolean,
  selected?: string
}

client.checkInternet()

Checks whether the dongle successfully connected to the provided WiFi network.

Returns

boolean

Internally interprets dongle field:

{ "RESULT_HOMEAP": 1 }

client.reboot()

Reboots the dongle.

Returns

{
  ok: boolean,
  rebooting: boolean
}

client.close()

Closes the underlying transport connection.

Should be called when provisioning flow is complete.


Command Mapping

The SDK maps high-level methods to numeric command IDs:

| Method | Command ID | |--------|------------| | getWifiList() | 3 | | selectWifiNetwork() | 1 | | checkInternet() | 2 | | reboot() | 7 |


Lifecycle Best Practices

Typical provisioning flow:

sequenceDiagram
    participant App
    participant Phone
    participant Dongle

    Note over Phone: User connects phone to<br/>Dongle WiFi network

    App->>Dongle: DongleClient.create("react-native")
    App->>Dongle: connect()

    App->>Dongle: getWifiList()
    Dongle-->>App: { APList: [...] }

    App->>Dongle: selectWifiNetwork(ssid, password)
    Dongle-->>App: { ok: true }

    App->>Dongle: checkInternet()
    Dongle-->>App: { RESULT_HOMEAP: 1 }

    App->>Dongle: reboot()
    Dongle-->>App: { rebooting: true }

    App->>Dongle: close()

Always call close() after finishing.


Error Handling

The SDK throws when:

  • TCP connection fails
  • Socket errors occur
  • JSON response cannot be parsed
  • Transport not connected

You should wrap provisioning flows in try/catch.

Example:

try {
  await client.connect();
  await client.selectWifiNetwork(ssid, password);
} catch (err) {
  console.error("Provisioning failed:", err);
}

Limitations

  • Assumes strict request → single response pattern
  • No multiplexing
  • No built-in retry logic
  • No internal timeout management
  • "node" transport may not yet be implemented

Extending the SDK

To add a new dongle command:

  1. Add command ID in core/commands.js
  2. Add a wrapper method in DongleClient
  3. Call transport.sendCommand(commandId, params)

To add a new transport:

  1. Implement connect, sendCommand, close
  2. Register it in DongleClient.create()

License

Commercial © Jemac Sweden AB