DevelopersDocumentation

React hook — useKeonWiFi

Keon WiFi SDK → React hook

@feelrobotics/keon-wifi-sdk-react wraps the core SDK in a single React hook. It manages the active controller across all three transports and closes the connection automatically when the component unmounts. The core SDK is re-exported, so everything can be imported from one package.

Install

npm install @feelrobotics/keon-wifi-sdk-react @feelrobotics/keon-wifi-sdk react

Peer dependency: react >= 16.8.0.

Usage

import { useKeonWiFi } from '@feelrobotics/keon-wifi-sdk-react';

function DeviceControl({
  partnerToken,
  deviceConnectionKey,
}: {
  partnerToken: string;
  deviceConnectionKey: string;
}) {
  const { controller, status, connectFug, disconnect } =
    useKeonWiFi(partnerToken);

  return (
    <>
      <button onClick={() => connectFug({ deviceConnectionKey })}>
        Connect
      </button>
      {status && <p>Battery: {status.battery_status}%</p>}
      <button onClick={() => controller?.moveTo(50, 90)}>Move</button>
      <button onClick={() => controller?.stop()}>Stop</button>
      <button onClick={disconnect}>Disconnect</button>
    </>
  );
}

API

useKeonWiFi(feelAppsToken) returns:

Field Description
controller Active KeonController for BLE, WiFi, or FUG, or null.
status Primary device KeonDeviceStatus from the remote status list, or null.
statuses Latest KeonDeviceStatus[] for every device on the WiFi/FUG connection.
position Latest BLE motor position notification, or null.
connectFug({ deviceConnectionKey, statusPollIntervalSec? }) Recommended. Connect the FUG REST controller.
connectWifi(registrationToken) Direct Socket.IO connection to the FEC server for near-real-time commands. Get the token from the core SDK’s getTokenForKeonWiFi().
connectBle() BLE fallback; updates position from notifications.
disconnect() Close the active controller and reset hook state.

A live demo of this hook is available in the React Hook Sandbox.


← BleManager — Web Bluetooth · Next: React Hook Sandbox