NeoBeeShell¶
NeoBeeShell is the main class to interact with the controller programmatically. The purpose if the library is to read and write the configuration settings. The library uses a tcp communication. So to use the library, you do not need the serial line of the usb cable. The benfit of this approach is, that you are able to accessthe board remotely as long as you are in the same network.
Because a tcp socket is used, it is important to close the socket at the end. The NeoShell class implements pythons context protocol. Therefore you can use it in a with clause, which garantuees to close the socket. No need to open and close the socket. Thats all managed for you in the background. It makes code safer and more human readable.
Here’s an example:
with NeoBeeShell(host="192.168.178.80") as s:
name = s.name
s.wifi_password = "mysecret"
s.save_configuration()
API Documentation¶
-
class
neobee.shell.
NeoBeeShell
(host='192.168.4.1', port=8888)¶ The NeoBeeShell is the main class to configure the controller programmatically. The class implements pythons context protocol. To use this class, you have to be in the same network as the controller. When the controller acts as an access point, connect to the controller before using the class.
When using with the
with
clause, the class connects before executing the statements and disconnects at the end. Even if an exception occurs. This is the preferred way to use the class.- Parameters
host (str, optional) – The IP of the controller. Defaults to 192.168.4.1
port (int) – The port to connect to. Defaults to 8888
-
calibrate
(ref_weight: int, count: int)¶ Calibrates the scale. Before calibrating the scale, be sure, to tare the scale correctly.
To calibrate the weight, a reference weight is needed. And the value you provide determines the unit to be used.
Example:
Put a weight of 1 kilogramm onto the scale. If you now call this method with a ref_weight of 1, all measurements are done in kilogramm. If you call this method with a value of 1000, all measurements are done in gramm.
-
connect
()¶ Connects to the controller. If a connection already has been established, an AlreadyConnectedError is raised.
The preferred way to use this class is in a with statement, which eliminates the need to connect or disconnect explicitly.
-
property
connected
¶ Boolean flag indicating if the controller is connected or not.
-
disconnect
()¶ Disconnects from the controller. If no connection has been established, an NotConnectedError is raised.
-
erase_settings
()¶ Removes the stored settings from flash memory. After a reboot, the board acts as a AP again.
-
property
info
¶ Returns a NeoBeeInfo object, which contains all the current settings.
-
property
mac_address
¶ Returns a MacAddress object with the mac address of the board.
-
property
name
¶ String property for the name of the board. The length of the name is limited to 20 and is expected to be in ascii encoded.
If a name longer then 20 characters is provided, a DataError is raised.
-
save_settings
()¶ Stores the settings to the flash memory.
-
property
scale_factor
¶ Float property for the scale factor.
-
property
scale_offset
¶ Float property for the offset of the scale.
-
property
ssid
¶ String property for the ssid of the wifi network.
-
tare
(nr_times: int)¶ Command to trigger the taring.
Taring is the process to determine the 0 value of the scale. So, before triggering this command, empty the scale.
nr_times specifies the number of measurements excecuted to calculate the tare as an average of the measured values.
-
property
temperature
¶ Reads the temperature of both sensors. Returns the temperature as a float value in celsius degree.
-
property
version
¶ Returns the version of the firmware as a tuple (MAJOR, MINOR, BUILD).
-
property
wifi_password
¶ String property for the wifi_password.