Package Modules¶
-
class
smartagro.smart.
SmartAgro
[source]¶ Implemented After searching for a broker Instantiates an object which has sensors added to it then configures a broker. Sensors are attached added with corresponding topics Sensor Data is published and Actuator can be activated
-
activate_actuator
(gpio_pin, state)[source]¶ A function to activate or deactivate an actuator.
Parameters: - gpio_pin (int) – GPIO pic of connected actuator.
- state (bool) – State whether it is on or Off
-
config_broker
(broker='test.mosquitto.org', qos=0, port=1883, stream_schema='json')[source]¶ Function to configure a new broker to be published to.
Parameters: - broker – The url or ip address of the broker.
- qos – quality of service determining how many times message is sent. 0,1,2
- port – broker port in use. default 1883, ssl 8883
- stream_schema – the data stream schema used. Default is json
Returns: mqtt client object
-
get_dht
()[source]¶ A function to get readings from the single wire DHT11 device.
Returns: Temperature and Humidity Readings
-
static
on_connect
(client, userdata, flags, rc)[source]¶ The callback for when a connection is established with the server.
Parameters: - client – Mqtt Client
- userdata – Authentication data
- flags – Connection indicators
- rc – status code of connection
-
static
on_message
(client, userdata, msg)[source]¶ The callback for when a PUBLISH message is received from the server.
Parameters: - client – MQtt client
- userdata – data used for authenticated connections
- msg – received message topic and payload in bytes
-
read_all
()[source]¶ A function to read all the values at once
Returns: A list of current moisture, light, temperature, humidity values
-
Utilities Module. With several functions that are repeatedly used
-
smartagro.utils.
discover_i2c
()[source]¶ Scans address space and ports to discover connected I2C or SPI devices uses os i2cdetect for the 1 I2C port and also scans two SPI ports
-
smartagro.utils.
find_broker
()[source]¶ Scan for online MQTT brokers then scan within network by checking online hosts then scanning for open MQTT ports
Returns: No return
-
smartagro.utils.
gpio_init
()[source]¶ Function to initialize the GPIO pins, numbering system used and communication protocols. GPIO.BCM IS THE DEFAULT
-
smartagro.utils.
read_analogue
(channel, spi_device=0, baud=1350000)[source]¶ Reads an analogue signal from the connected SPI ADC device and returns channel reading.
Parameters: - channel (int) – ADC channel where sensor is connected.
- spi_device (int) – Either 0 or 1 as there are only 2 spi ports
- baud (int) – the bit rate, measured in bit/s clock rate used for device
Returns: Raw 1024 bit ADC output data.
-
smartagro.utils.
scan_network
()[source]¶ Ger the IP address other than the loopback IP that the device has been allocated by DHCP Scan subnet /24 of IP address to check for LAN brokers’ availability.
Returns: list of online devices responding to ICMP echo request using ping.
-
smartagro.utils.
switch_actuator
(gpio_pin, state)[source]¶ Function to switch actuator ON or OFF
Parameters: - gpio_pin (int) – The pin the fan relay (motor in demo) is connected to.
- state (boolean) – Boolean indicating whether fan is on or off.