This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Modify Light Switch Example on nRF5 Mesh SDK v3.0.0

I am a beginner and I need to know how we can further modify the light switch example codes to access gpio pins and get some output from that.

I have run the example using nRF Mesh App as the provisioner.

I want to code such that when each of the buttons on the client is pressed, for a customized task to happen. That means for example to light an external LED connected to a GPIO pin on a server. And I want to know how we can configure tasks like that to each button. Should I modify both client and server codes ? Where should I modify ?

I also want to know how I can add more elements to the client so that it can publish to many servers. I could only publish to two servers for now. For that, can elements be added in the nRF Mesh app ? Or should I edit the codes ?

Also, as unicasting is done here, I want to know how I can broadcast using this example. 

  • Hello,

    This is possible, but it would require some modifications to the example.

    To put it really simple. If you have one server and one client (and one provisioner), the thing that happens when you press one of the buttons on the client DK is that the button_event_handler in the client example's main.c file is called. If you press button 1, then the set_params.on_off is set to APP_STATE_ON (true), and if you press button 2 it is set to APP_STATE_OFF.

    Now, the on_off_model only contains a bool variable for the state of the on_off model, so you would have to change this model in order to send more than one bit of information. If you replace the generic_onoff_model with a custom model, containing e.g. one byte of information (you can do this by modifying the on_off model), and then change the button_event_handler to send different values, depending on what button that is pressed (make sure to change both the server and client). The different buttons will change the button_number in button_event_handler(uint32_t button_number);

    On the Server example, the callback function you get when you press the button on the server is the app_onoff_server_set_cb(). Now, when you have changed the model to contain a byte (uint8_t instead of a bool), you can toggle the pins according to this value.

    Best regards,

    Edvin

Related