Class Service

extends Object

Class summary


constructor --key/Key= --rate/int= --channel/int= --buffer-byte-size/int= --queue-size/int=
Constructs a new ESP-Now service in station mode.

Constructors

constructor --key/Key=null --rate/int=RATE-1M-L --channel/int=6 --buffer-byte-size/int=2048 --queue-size/int=8
Constructs a new ESP-Now service in station mode.
The rate parameter, if provided, must be a valid ESP-Now rate constant. See RATE-1M-L for example. By default, the rate is set to 1Mbps.
The master key, if provided, encrypts the local keys that are used for direct communication given with add-peer. If none is provided, a default one is used. Note that this master key is only used if the peer is added with a key. Any communication with peers that don't have their own local keys is unencrypted even if a master key is provided.
The channel parameter must be a valid WiFi channel number.
Advanced
The buffer-byte-size parameter sets the size of the internal buffer used for receiving messages. It is used to store incoming messages until they are handled by receive. If a message is received that is larger than the remaining space in the buffer, previous unhandled messages are dropped. If a message is larger than the entire buffer, it is dropped. By default the buffer size is 2048 bytes. Its size must be a multiple of 128.
The queue-size parameter sets the size of the internal queue used for receiving messages. It is used to queue incoming messages until they are handled by receive. If a message is received when the queue is full, the oldest message in the queue is dropped. By default the queue size is 8.
By dropping old messages, the service ensures that the most recent messages are always received, at the cost of potentially losing some older ones. This is especially important when starting to receive, as there might be unimportant messages already in the buffer that were sent before receive was called.

Statics

station --key/Key=null --rate/int=RATE-1M-L --channel/int=6 -> Service
Deprecated. Use Service.constructor instead.

Methods

add-peer address/Address --key/Key=null --mode/int=MODE-11G --rate/int=rate_ -> none
Adds a peer with the given address, key, mode and rate.
The channel of the peer is set to the channel of the service.
If a local key is provided, it is used for any communication with that peer. That same key is also encrypted with the master key provided during construction. This means that both the master key and the local key must be the same on both sides of the communication. If no local key is provided, communication with that peer is unencrypted, even if a master key was provided during construction.
The rate must be one of the ESP-Now rate constants. See RATE-1M-L for example. By default the one provided at construction is used.
For long-range operation use mode set to MODE-LR and rate set to RATE-LORA-250K or RATE-LORA-500K.

close -> none

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Receives a datagram.
Blocks until a datagram is received.

remove-peer address/Address -> none
Removes the peer with the given address.
Once removed, the same address can be used again in add-peer.

send data/ByteArray --address/Address --wait/bool -> none
Deprecated. The wait flag is ignored.

send data/Data --address/Address -> none
Sends the given data to the given address.
Unless the address is a broadcast address, the address must be a peer added with add-peer address --key. The address must be a valid MAC address.
The data must be at most 250 bytes long.
Waits for the transmission to complete.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

Fields