pamoja for TypeScript - v0.2.0
    Preparing search index...

    Class EndDevice

    A LoRaWAN Class A end device, without a radio.

    It joins, chooses a channel and data rate for each uplink, says when and where to listen for the answer, reads what comes back, and does what the network's MAC commands ask. It owns no radio and no clock: every call takes the time in microseconds and hands back what to put on the air, so the same device runs over any radio, or in a test with none.

    One exchange runs like this. EndDevice.join or EndDevice.send returns a transmission and two receive windows timed from its end. A frame heard in either window goes to EndDevice.heard. If neither held one, EndDevice.nothingHeard says whether to EndDevice.repeat the frame, or move on.

    A call that cannot be done throws a DeviceError; isDeviceError tells which.

    const device = EndDevice.overTheAir(planFor(LoraRegion.Eu868), devEui, joinEui, appKey, {
    minOutputDbm: 2,
    maxOutputDbm: 14,
    })
    const request = device.join(nonce, clock.nowUs())
    Index
    • get dataRate(): number

      The data rate the next uplink goes out at, before any back-off step.

      Returns number

    • get devAddr(): number | null

      The address the device is on the network by, or null before joining.

      Returns number | null

    • get fcntDown(): number | null

      The last downlink frame counter accepted, or null before any downlink.

      Returns number | null

    • get fcntUp(): number

      The next uplink frame counter, which a device stores to carry over a restart.

      Returns number

    • get isJoined(): boolean

      Whether the device is on a network: once joined, or from the start when personalized.

      Returns boolean

    • get receiveDelayUs(): number

      The delay from the end of an uplink to the first receive window, in microseconds.

      Returns number

    • get relaying(): boolean

      Whether the next uplink goes through a relay.

      Returns boolean

    • get relayStatus(): lorawan.RelayStatus | null

      What the relay's last acknowledgment said about itself, or null before one arrived.

      Returns lorawan.RelayStatus | null

    • get relaySync(): LorawanRelaySync

      What the device knows of when its relay listens, TS011-1.0.1 section 3.9.

      Returns LorawanRelaySync

    • get rx2(): lorawan.Rx2

      Where the second receive window listens.

      Returns lorawan.Rx2

    • get transmissions(): number

      How many times each uplink goes out, as the network last set it.

      Returns number

    • get worCounter(): number

      The WOR frame counter the next frame will use, TS011-1.0.1 section 5.3.2.

      Returns number

    • Lists the channels the device may send on.

      Returns lorawan.Channel[]

      Each enabled channel, with its index.

    • Reads a frame heard in one of the receive windows of the last transmission.

      TS001-1.0.4 section 4.1 has a device discard a frame whose MACPayload is longer than the data rate it was received at carries. Name the window and the frame is held to that window's limit; leave it out and it may be as long as the faster window allows.

      Parameters

      • frame: Uint8Array

        The bytes the radio received.

      • snrDb: number

        The frame's signal-to-noise ratio, which a DevStatusAns reports.

      • Optionalwindow: LorawanReceiveWindow

        The window the radio heard it in, when known.

      Returns lorawan.Heard

      The join, or the downlink read and acted on.

      A DeviceError: NothingPending, Foreign, Replayed, CounterGap, Refused or Frame. The windows stay open, so the second still listens.

    • Reads the acknowledgment a relay answered the last WOR frame with.

      The device is now synchronized: it knows when the relay scans, so its next frames carry only as much preamble as the two clocks could have drifted apart.

      Parameters

      • frame: Uint8Array

        The seven bytes the radio received in the acknowledgment window.

      Returns lorawan.RelayStatus

      What the relay said about itself.

      A DeviceError: NothingPending with no exchange waiting, or Frame for an acknowledgment that does not verify.

    • Builds a join request.

      Parameters

      • devNonce: number

        A nonce this device has never used with its join EUI.

      • nowUs: number

        The time, in microseconds.

      Returns lorawan.Transmission

      What to transmit, with the join accept windows.

      A DeviceError: NoCredentials, Busy or Wait.

    • Says what comes next once both receive windows closed with nothing for the device.

      Parameters

      • nowUs: number

        The time the second window closed, in microseconds.

      Returns lorawan.Next

      Whether to repeat the frame, join again, or move on.

      A DeviceError: NothingPending.

    • Says what to do once the acknowledgment window closed with nothing in it.

      Parameters

      • nowUs: number

        The time the window closed, in microseconds.

      Returns lorawan.WorNext

      Whether to send the uplink at the time the exchange named anyway, or wake the relay again first, as the network's back-off asks.

      A DeviceError: NothingPending.

    • Sends the last uplink again, the same frame on a channel chosen afresh.

      Parameters

      • nowUs: number

        The time, in microseconds.

      Returns lorawan.Transmission

      What to transmit, with its receive windows.

      A DeviceError: NothingPending or Wait.

    • Asks the network, with the next uplink, for the time.

      Returns void

    • Asks the network, with the next uplink, how well it hears the device.

      Returns void

    • Puts a saved state back on a device made the same way.

      Parameters

      • saved: Uint8Array

        The state EndDevice.save returned.

      • nowUs: number

        The time on the clock the device woke to, in microseconds.

      Returns void

      A DeviceError: State for a state of the wrong length, a corrupt one, one in another format, or one from another plan, and Busy.

    • Saves a joined device's state, to keep across a loss of power.

      The bytes hold the session keys, so keep them wherever the keys would be safe.

      Parameters

      • nowUs: number

        The time, in microseconds.

      Returns Buffer

      The state.

      A DeviceError: NotJoined or Busy.

    • Builds an uplink carrying a payload.

      Parameters

      • port: number

        The application port, 1 to 223, or 224 for the certification test port.

      • payload: string | Uint8Array<ArrayBufferLike>

        The payload, as bytes or text encoded as UTF-8.

      • nowUs: number

        The time, in microseconds.

      • Optionalconfirmed: boolean

        Whether to ask the network to acknowledge it.

      Returns lorawan.Transmission

      What to transmit, with its receive windows.

      A DeviceError: NotJoined, Busy, Wait, PayloadTooLong, or Frame for port 0.

    • Builds an uplink with no payload, carrying the answers the device owes, an acknowledgment, or an ADR acknowledgment request.

      Parameters

      • nowUs: number

        The time, in microseconds.

      Returns lorawan.Transmission

      What to transmit, with its receive windows.

    • Sets what the device reports its battery as when a network asks.

      Parameters

      • battery: number | "external" | "unknown" | null

        A level from 1, empty, to 254, full; 'external' on external power; or 'unknown' or null when it cannot tell.

      Returns void

    • Turns relay mode on or off, TS011-1.0.1 section 10.2 and appendix 5.

      From here on the decision is the caller's rather than the device's own policy, until the network takes it over with an EndDeviceConfReq or hands it back.

      Parameters

      • on: boolean

        Whether the next uplinks go through a relay.

      Returns boolean

      false when the network holds the decision, leaving the mode as it was.

    • Makes a device that joins over the air.

      Parameters

      • plan: lora.LoraChannelPlan

        A published channel plan, from planFor or cn470Plan.

      • devEui: Uint8Array

        The 8-byte device EUI.

      • joinEui: Uint8Array

        The 8-byte join EUI.

      • appKey: Uint8Array

        The 16-byte root key.

      • settings: lorawan.DeviceSettings

        What the radio can do; only the output power range is required.

      • Optionalcounters: lorawan.FrameCounters

        Frame counters carried over a restart; a join starts them over.

      Returns lorawan.EndDevice

      The device, not yet joined.

      If the plan was built rather than published, a credential is the wrong length, or the settings run backward.

    • Makes a device activated by personalization.

      Such a device never resets its frame counters, so one that lost power passes the ones it kept.

      Parameters

      • plan: lora.LoraChannelPlan

        A published channel plan.

      • devAddr: number

        The address the device was provisioned with.

      • nwkSKey: Uint8Array

        The 16-byte network session key.

      • appSKey: Uint8Array

        The 16-byte application session key.

      • settings: lorawan.DeviceSettings

        What the radio can do.

      • Optionalcounters: lorawan.FrameCounters

        The frame counters the device kept.

      Returns lorawan.EndDevice

      The device, ready to send at its slowest data rate.

      If the plan was built rather than published, or a key is the wrong length.