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 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

    • 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 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 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 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 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 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.

    • 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.

      • confirmed: boolean = false

        Whether to ask the network to acknowledge it.

      Returns Transmission

      What to transmit, with its receive windows.

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

    • 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: 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: DeviceSettings

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

      • Optionalcounters: FrameCounters

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

      Returns 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: 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: DeviceSettings

        What the radio can do.

      • Optionalcounters: FrameCounters

        The frame counters the device kept.

      Returns 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.