@iotile/iotile-device
Version:
A typescript library for interfacing with IOTile BLE devices
265 lines (253 loc) • 10.5 kB
TypeScript
import { AbstractIOTileAdapter } from './iotile-base-types';
/**
* All known short codes for converting settings into string names.
*/
export declare enum SettingCodes {
IPConfig = 0,
NetworkName = 1,
NetworkKey = 2,
SharedConnection = 3,
InterfaceIndex = 4,
ModemAPN = 5
}
export declare enum NetworkInterfaces {
Ethernet = 0,
Wifi = 1
}
/**
* A simple class for holding an IPV4 address and converting between representations
*/
export declare class IPV4Address {
address: any;
private _parts;
constructor(address: any);
/**
* Return the dotted address as a single 32 bit integer
*
* X.Y.Z.W returns 0xXXYYZZWW
*/
asUint32(): number;
toString(): string;
isEqual(ip1: IPV4Address, ip2: IPV4Address): boolean;
}
/**
* A data class encapsulating a wifi or cellular network.
*/
export declare class WirelessNetwork {
static NO_AUTH: number;
static WPA2_PSK_AUTH: number;
static WPA2_ENTERPRISE: number;
static WEP_AUTH: number;
static UNKNOWN_AUTH: number;
static CELLULAR: number;
static AUTH_TABLE: {
[x: number]: string;
};
ssid: string;
authType: number;
quality: any;
valid: boolean;
/**
*
* @param ssid
* @param authType
* @param quality
*/
constructor(ssid: string, authType: number, quality?: number | null);
/**
* Rebuild a WirelessNetwork from one or more encoded chunks.
*/
static FromEncodedChunks(encodedChunks: ArrayBuffer[]): WirelessNetwork;
static InvalidNetwork(): WirelessNetwork;
requiresPassword(): boolean;
toString(): string;
encode(nameOffset: number): ArrayBuffer;
}
export declare class NetworkInterfaceInfo {
id: any;
configured: boolean;
autoconnect: boolean;
valid: boolean;
static: boolean;
sharing: boolean | null;
error: number;
type: any;
carrier: any;
private _ip4Addr;
private _ip4Gateway;
private _ip4Netmask;
private _ip4DNS;
constructor(ifaceId: any, configured: boolean, ifaceType: any, carrier: any);
readonly address: IPV4Address;
readonly gateway: IPV4Address;
readonly netmask: IPV4Address;
readonly dnsServers: IPV4Address[];
/**
* Build a NetworkInterfaceInfo object from an RPC response
* @param {Arraybuffer} data The 20 byte packed binary data produced
* by a call to asRPCPayload
*/
static FromRPC(data: ArrayBuffer): NetworkInterfaceInfo;
static ParseFlags(flags: number): [number, boolean, boolean, boolean, boolean, boolean];
/**
* Configure the ip address information for this interface.
*/
setIp4Info(addr: any, gateway: any, netmask: any): void;
addDNS(addr: any): void;
toString(): string;
invalidInterface(ifaceId: number): NetworkInterfaceInfo;
/**
* Pack this interface status as a an RPC response payload
*/
asRPCPayload(): ArrayBuffer;
_packFlags(): number;
}
/**
* Class to configure the network for a raspberry pi based access point
*/
export declare class NetworkConfig {
private adapter;
private address;
constructor(adapter: AbstractIOTileAdapter, address: number);
/**
* Capture and count the network interfaces on this device.
*
* This function must be called before any other interface related
* functions are called since it captures the network devices for
* future access.
*
* The interfaces may be accessed by index after calling this function
* and their index number will always point to the same device until
* this function is called again.
*
* @returns {Promise<number>}: The count of network devices.
*
* @param address
*/
listInterfaces(): Promise<any>;
/**
* Get basic information about a network interface.
*
* This information includes the type of interface, whether it is currently
* connected to a media / ethernet cable and what its IP information is.
*
* @returns {Promise<string>} InterfaceInfo show-as string: An InterfaceInfo structure with the interface info.
*
* @param {number} index The index of the interface we wish to query.
* This must be < the count returned by list_interfaces.
*/
interfaceInfo(index: number): Promise<NetworkInterfaceInfo>;
/**
* List all visible networks for a given interface.
*
* @returns {Promise<string[]>} A list of visible WirelessNetwork objects
*
* @param {number} index A network interface index.
*/
listNetworks(index: number): Promise<WirelessNetwork[]>;
/**
* Get the active network for a given interface.
*
* @returns {Promise<string>} WirelessNetwork show-as string: The active wireless network.
*
* @param {number} index A network interface index.
*/
activeNetwork(index: number): Promise<WirelessNetwork>;
/**
* Get information on a given wireless network.
You must have previously called list_networks to capture network
information from a given interface and then you can iterate over those
results by calling this function. If the network name is longer than
20 bytes, you can call this function with a nonzero offset in order to
retrieve the higher parts of the name. The same header information is
repeated with each call, not just when offset=0.
The response contains:
- Network auth type and flags
- Signal quality
- Total name length
- Valid name length in this segment
- up to 16 bytes of the access point ssid or carrier name depending on whether
the network is wifi or cellular.
To enquire about the active network for the interface, pass -1 as the
index.
* @param {number} index The index of the network to enquire about. Pass -1 to
* ask about the active network
*/
networkInfo(index: number): Promise<WirelessNetwork>;
/**
* Setup a basic wifi connection.
You need to enter the network ssid and password (if there is one). If
you want a default dhcp based connection those are the only settings
you need. Otherwise, you can specify a static IP address by passing
static_ip, dns, netmask and gateway.
If you want to create a wifi hotspot, you can pass shared=True and the
network name and password are used to create a wifi hotspot. If you
combine shared=True with a static IP then you can set the IP of the
node and the netmask it will use to allocate IPs for other computers
connecting to its hotspot. The dns and gateway options are ignored if
shared=True.
* @param {number} iface The index of the interface that we wish to configure as
a wifi network. This should be a wifi type interface.
* @param {string} networkName The ssid of the network that you wish to join
* @param {string} password An optional password for the network
* @param {string} staticIp An optional static ipv4 address in X.Y.Z.W format
* @param {string} dns An optional dns server in X.Y.Z.W format, only used if
combined with static_ip.
* @param {string} netmask An optional netmask in X.Y.Z.W format, only used if
combined with static_ip.
* @param {string} gateway An optional default gateway for routing traffic. Only
used if combined with static_ip.
* @param {boolean} shared Whether to setup the interface as a hotspot or not.
*/
configWifi(iface: number, networkName: string, password?: string, staticIp?: (string | null), dns?: (string | null), netmask?: (string | null), gateway?: (string | null), shared?: boolean): Promise<void>;
/**
* Set up the ethernet configuration of a device. Currently only designed for static ip allocation.
*
* @param {number} iface The index of the interface that we wish to configure as
an ethernet network. This should be a wifi type interface.
* @param {string} staticIp An optional static ipv4 address in X.Y.Z.W format
* @param {string} dns An optional dns server in X.Y.Z.W format, only used if
combined with static_ip.
* @param {string} netmask An optional netmask in X.Y.Z.W format, only used if
combined with static_ip.
* @param {string} gateway An optional default gateway for routing traffic. Only
used if combined with static_ip.
*/
configEthernet(iface: number, staticIp?: (string | null), dns?: (string | null), netmask?: (string | null), gateway?: (string | null)): Promise<void>;
/**
* Begin pushing settings for a new configuration.
*/
beginConnection(): Promise<any>;
/**
* Finish pushing settings for a new configuration.
*/
finishConnection(index: any): Promise<void>;
/**
* Push a config setting by short id code.
*/
pushConfigSetting(settingCode: SettingCodes, value: any): Promise<void>;
encodeValue(value: any): ArrayBuffer;
private _pushSettingValueChunk;
/**
* Get information on a given wireless network.
You must have previously called list_networks to capture network
information from a given interface and then you can iterate over those
results by calling this function. If the network name is longer than
20 bytes, you can call this function with a nonzero offset in order to
retrieve the higher parts of the name. The same header information is
repeated with each call, not just when offset=0.
The response contains:
- Network auth type and flags
- Signal quality
- Total name length
- Valid name length in this segment
- up to 16 bytes of the access point ssid or carrier name depending on whether
the network is wifi or cellular.
To enquire about the active network for the interface, pass -1 as the
index.
* @param index
* @param offset
*/
private _networkInfoChunk;
private _captureNetworkList;
}