Nanpy

Nanpy allows you to connect to a microcontroller and control it via serial or wifi. Supported microcontrollers include ESP8266, ESP32 and arduino

Installing Nanpy

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.

Extension Configuration

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.

Once you have nanpy connected you can utilize the various interfaces to setup components for the device.

Sensor Interface

One of the main reasons we attached nodes to our system is for the sensor support. There are several sensor types currently available. Arduinos and ESPs have a larger range of supported sensor types due to the analog GPIO.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the sensor
node[String]Yeskey of the node connection to use.
pin[Integer]YesGPIO pin number on arduino the sensor is connected to.
type[String]YesType of sensor. Options: gpio, dht.
name[String]NoFriendly name of the sensor. Useful for UI.
analog[Boolean]NoSet to true if the pin is analog. Default: false
classifier[String]NoClassifier override for sensor formatting.

DHT Sensor Settings

Here are some settings for the dht sensor type.

OptionTypeRequiredDescription
model[String]NoModel of DHT device to use. Options: 11, 22 or 2302. Default: 11

Config

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

Control Interface

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.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
node[String]Yeskey of the node connection to use.
pin[Integer]YesGPIO pin to use on board i.e. 12.
name[String]NoFriendly display name of component. Useful for UI.
type[String]NoType of control behavior. Options: button control or potentiometer. Default: button
analog[Boolean]NoSet to true if the pin is analog. Default: false
buffer[Integer]NoA buffer to apply to analog readings in order ot prevent many state updates for small variances in readings.

Config

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

Toggle Interface

Provides a toggle that can turn a nanpy device GPIO pin on or off.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
node[String]Yeskey of the node connection to use.
pin[Integer]YesGPIO pin to use on board i.e. 12.
name[String]NoFriendly display name of component. Useful for UI.
max_duration[Integer]NoFailsafe duration (in seconds) to turn off toggle after. 0 means off. Default 0
invert_state[Boolean]NoSet to True if toggle is off when pin is in HIGH state. Default False

Config

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

Character Display Interface

Connect and control a character display over I2C to display messages.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
address[Integer]YesThe i2c address of the display (as an integer) Default: 39.
node[String]Yeskey of the node connection to use.
type[String]NoWhat type of display is connected. Options: i2c or gpio. Default i2c
default_duration[Integer]NoTime in seconds for messages to be displayed on screen by default when no duration is provided. Default: 5
max_duration[Integer]NoThe max time in seconds that messages can be on the screen. Default: 60
message_limit[Integer]NoNumber of messages to accept into queue before overwriting. Default: 20
topic[Integer]NoChannel to listen for events on. Default: char_display/{key}
name[String]NoFriendly display name of component. Useful for UI.

Config

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