Nanpy allows you to connect to a microcontroller and control it via serial or wifi. Supported microcontrollers include ESP8266, ESP32 and arduino
Nanpy allows us to issue commands over serial or wifi to our device from our controller running MudPi. You will need to compile and install the nanpy firmware on your device using the arduino IDE. Please be sure to use the custom MudPi fork of nanpy for ESP32 support. When setting up Nanpy you can choose to use serial or Wifi for the connection. To use wifi you need to add your network credentials in the firmware before you flash.
Then using a USB to TTL USB serial module you can connect your Nanpy device through a USB slot from your MudPi controller. ESP modules are also able to be programed over the arduino IDE and connect via serial through the same process.
If you are using Wifi the device should automatically connect to the network once powered. You can use the serial monitor of the arduino IDE to get the IP address or locate it through your router admin page. You will need the IP for your configs.
Once you have a Nanpy device connected, all that you need to do is update your mudpi config file to include your nanpy configuration and restart MudPi. The nanpy connection config is stored on the nanpy extension in order to consolidate the connection logic. Components can reference this connection to prevent multiple connection attempts and spamming parallel requests. An example of the configuration is listed below:
"nanpy": [
{
"key" : "nanpy_1",
"address": "192.168.2.150",
"use_wifi":true,
},
{
"key" : "nanpy_2",
"address": "/dev/ttyUSB0"
}
]}
The most important option to connect to your device is the address
, which is the USB device path or IP address. You can run ls /dev
in your terminal to get a listing of serial devices. Typically the value your looking for is one of /dev/AMA0
, /dev/ttyUSB0
, or /dev/ttyUSB1
.
MudPi will attempt to connect to the device and make an active connection. In the event a communication event occurs MudPi will attempt to reconnect while waiting a random delay before doing so. This random delay will increase with the number of failed attempts to help prevent failed connection spamming. If you wish to change the max delay inbetween connection attempts you can change the max_reconnect_delay
option which is the time it would wait in seconds.
Once you have nanpy connected you can utilize the various interfaces to setup components for the device.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the sensor |
node | [String] | Yes | key of the node connection to use. |
pin | [Integer] | Yes | GPIO pin number on arduino the sensor is connected to. |
type | [String] | Yes | Type of sensor. Options: gpio , dht . |
name | [String] | No | Friendly name of the sensor. Useful for UI. |
analog | [Boolean] | No | Set to true if the pin is analog. Default: false |
classifier | [String] | No | Classifier override for sensor formatting. |
Here are some settings for the dht
sensor type.
Option | Type | Required | Description |
model | [String] | No | Model of DHT device to use. Options: 11 , 22 or 2302 . Default: 11 |
Here is a config of a complete nanpy sensor.
"sensor": [{
"key": "nanpy_gpio_d12",
"interface": "nanpy",
"node": "nanpy_1",
"name": "GPIO Pin D12",
"type": "gpio",
"pin": 12,
"analog": false
}]
Arduinos and ESPs have analog GPIO support and allow us access to a larger range of control options. Below is a list of available control settings.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
node | [String] | Yes | key of the node connection to use. |
pin | [Integer] | Yes | GPIO pin to use on board i.e. 12 . |
name | [String] | No | Friendly display name of component. Useful for UI. |
type | [String] | No | Type of control behavior. Options: button control or potentiometer . Default: button |
analog | [Boolean] | No | Set to true if the pin is analog. Default: false |
buffer | [Integer] | No | A buffer to apply to analog readings in order ot prevent many state updates for small variances in readings. |
Here is a config of a complete nanpy control.
"control": [{
"key": "nanpy_control_a2",
"interface": "nanpy",
"node": "nanpy_1",
"name": "Potentiometer Pin A2",
"type": "potentiometer",
"pin": 2,
"analog": true,
"buffer": 15
}]
Provides a toggle that can turn a nanpy device GPIO pin on or off.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
node | [String] | Yes | key of the node connection to use. |
pin | [Integer] | Yes | GPIO pin to use on board i.e. 12 . |
name | [String] | No | Friendly display name of component. Useful for UI. |
max_duration | [Integer] | No | Failsafe duration (in seconds) to turn off toggle after. 0 means off. Default 0 |
invert_state | [Boolean] | No | Set to True if toggle is off when pin is in HIGH state. Default False |
Here is a config of a complete nanpy toggle.
"toggle": [{
"key": "nanpy_toggle_D12",
"interface": "nanpy",
"node": "nanpy_1",
"name": "LED - Pin D12"
"pin": 12,
"max_duration": 360,
"invert_state": false
}]
Connect and control a character display over I2C to display messages.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
address | [Integer] | Yes | The i2c address of the display (as an integer) Default: 39 . |
node | [String] | Yes | key of the node connection to use. |
type | [String] | No | What type of display is connected. Options: i2c or gpio . Default i2c |
default_duration | [Integer] | No | Time in seconds for messages to be displayed on screen by default when no duration is provided. Default: 5 |
max_duration | [Integer] | No | The max time in seconds that messages can be on the screen. Default: 60 |
message_limit | [Integer] | No | Number of messages to accept into queue before overwriting. Default: 20 |
topic | [Integer] | No | Channel to listen for events on. Default: char_display/{key} |
name | [String] | No | Friendly display name of component. Useful for UI. |
Here is a config of a complete i2c display.
"char_display": [{
"key": "i2c_display_1",
"interface": "nanpy",
"node": "nanpy_1",
"address": 39,
"name": "I2C LCD Display",
"type": "i2c",
"max_duration": 30,
"default_duration": 10,
"topic": "char_display/i2c_display_1",
"message_limit": 20
}]