I am working on creating a mesh network consisting of sensors and output devices.
I am using the serial example with interactive_pyaci to provision the network from a PC,
I would also like the PC to participate in the network as a node.
I can poll my sensors for the state of an input and I can set the state of an output, using the Gereric_OnOff model.
What I would like to do is have the PC receive a notification on input change.
I currently have the sensor set up to transmit using the access_model_publish(). How do I get the interactive_pyaci to subscribe to the messages, so it can respond to events.
This is the code on the sever side
uint32_t simple_input_server_status_publish(simple_input_server_t * p_server, bool value)
{
simple_input_msg_status_t status;
status.present_on_off = value ? 1 : 0;
access_message_tx_t msg;
msg.opcode.opcode = SIMPLE_INPUT_OPCODE_STATUS;
msg.opcode.company_id = SIMPLE_INPUT_COMPANY_ID;
msg.p_buffer = (const uint8_t *) &status;
msg.length = sizeof(status);
msg.force_segmented = false;
msg.transmic_size = NRF_MESH_TRANSMIC_SIZE_DEFAULT;
msg.access_token = nrf_mesh_unique_token_get();
return access_model_publish(p_server->model_handle, &msg);
}
This is derives from the simple_on_off_server.
I have not implemented a client on the serial board as I want the PC to perform the client functions
I am using Mesh sdk 3.1.0 and the interactive_pyaci script that cam with it. I have added the new model for the script
from mesh.access import Model, Opcode
import struct
class SimpleInputClient(Model):
SIMPLE_INPUT_STATUS = Opcode(0xe4, 0x5900, "Simple Input Status")
SIMPLE_INPUT_GET = Opcode(0xe2, 0x0059, "Simple Input Get")
def __init__(self):
self.opcodes = [
(self.SIMPLE_INPUT_STATUS, self.__simple_input_status_handler)]
self.__tid = 0
super(SimpleInputClient, self).__init__(self.opcodes)
def get(self):
self.send(self.SIMPLE_INPUT_GET)
@property
def _tid(self):
tid = self.__tid
self.__tid += 1
if self.__tid >= 255:
self.__tid = 0
return tid
def __simple_input_status_handler(self, opcode, message):
on_off = "on" if message.data[0] > 0 else "off"
self.logger.info("Input value is %s", on_off)