Skip to content

Add new library 'SmartSystem' to the library registry - simplified RPC over Wire and RF24 #5945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

mgfryan
Copy link
Contributor

@mgfryan mgfryan commented Feb 16, 2025

Add new library 'SmartSystem'. Readme below:

SmartSystem

SmartSystem is an Arduino library which simplifies building modular networks of Arduinos.

Functionality can be exposed by a Arduino module, and discovered, accessed, and executed remotely over either Wire or RF24 radio.

This library evolved from use of Arduinos in escape room setups, which required many Arduinos to be centrally controlled and monitored.

Installation

Use the Arduino library manager to install SmartSystem library.

At least 2 Arduinos are required to create a SmartSystem network.

If using Wire protocol

I2C Wire connections should use the default SDA and SCL pins for your Arduino (e.g. A4 / A5 for a Nano). This is not something that can be configured when using this library.

Using the Wire_Settings parameter at startup, it is possible to override the Wire connection speed.

If using an RF24 radio device (such as NRF24L01)

The default settings are those for UNO / Nano:

Connection Pin
CE 9*
CSN 10*
SCK (connect to board default - 13 for Nano)
MISO (connect to board default - 12 for Nano)
MOSI (connect to board default - 11 for Nano)
INTERRUPT 2*

Using the Radio_Settings parameter at startup, it is possible to override the pins marked with * in the table above. Note that using an INTERRUPT pin is absolutely required by this library!

Radio_Settings also let you control other selected parameters of the RF24 device, such as RADIO_SPEED, RADIO_POWER and CHANNEL (which defaults to 108),

In general, it is best to stick to the defaults where possible. This library generally favours simplicity and consistency over configurabilty!

Usage

The system setup always involves:

  • The SmartModules - These are Arduinos acting as providers of functionality for the network. There can be up to 64 of these on a single network.
  • A SmartController - A single main Arduino acting as system orchestrator

A SmartModule must always have strictly one communication method with the network - either Wire or RF24 Radio. This is selected at module startup using either startOverWire() or startOverRadio() function.

The SmartController can use either communication method, or both at once. It can see and control all connected modules, regardless of the communication protocol they are using. This is selected at controller startup using the usingWire() and usingRadio() methods.

SmartModule setup

Simple SmartModule Arduino sketch, which provides a function that returns an integer, exposed over RF24 radio

#include <SmartSystem.h>

// the number we want to return
volatile int answer = 42;

// Function we want to expose from the Arduino.
int theAnswer()
{
  return answer; // returns the answer variable
}

// sketch setup - set up the smart module here
void setup()
{
  // set up our Arduino as a smart module
  SmartModule
    .expose(theAnswer, "GetTheAnswer") // expose the function 'theAnswer', visible as 'GetTheAnswer'
    .addTag("Everything")              // tag the module (optional!) 
    .startOverRadio(1, "DeepThought"); // start as module 1 over Radio, with name "DeepThought"
}

// main sketch loop - nothing required here
// but code in loop() could, for example, read from a sensor, 
// and modify the variable to change the response
void loop()
{
}

SmartController setup

Simple SmartController Arduino sketch, which accesses the SmartModule's functionality over radio

#include <SmartSystem.h>

void setup() 
{
  // start up serial
  Serial.begin(9600);
  while (!Serial);

  // start up the controller, on both radio and wire, and scan for modules
  SmartController.usingRadio().usingWire().scan();

  // Find the desired module and function on the network
  // and execute it, expecting an integer return value
  int result = SmartController
                .module("DeepThought")
                .function("GetTheAnswer")
                .runToGet<int>();
  
  // print the output
  Serial.print("Invoke by name: GetTheAnswer returned: ");
  Serial.println(result);
}

void loop()
{  
}

Logging

To see more info on startup / connection issues, SmartController.doSerialErrorLogging(true) can be called at startup, which activates serial logging of any errors.

Gotchas

Because the exposed functions on the modules are invoked from interrupt callbacks, the following rules apply:

  • Do not use Serial logging within the exposed functions
  • Do not carry out any long-running operations in the exposed functions - delegate any work to the main loop.
  • Pass information between exposed functions and the rest of the sketch using variables marked as volatile

If you fail to observe the above, things can fail in unexpected and unpredictable ways.

Further information

The provided examples cover most use cases.

The AllMethodTypesModule.ino sketch shows how all different function types can be exposed from a module.

The UniversalController.ino is an interactive controller sketch, which shows how to scan, iterate over modules and functions, extract metadata from them, and invoke methods with all the allowed function signatures.

Using the sketches above on 2 Arduinos demonstrates all the possible ways of calling functions using a SmartSystem, and constitutes a good test when setting up a new system.

Contributing

Pull requests are welcome!

License

MIT

Add new library 'SmartSystem'
Copy link
Contributor

A problem was found with your submission https://bitbucket.org/mgf_ryan/smartsystem

ERROR: The repository has no tags. You need to create a release or tag that matches the version value in the library's library.properties file.

@github-actions github-actions bot added the topic: submission Add library to the list label Feb 16, 2025
Copy link
Contributor

Thanks for your interest in contributing to the Arduino Library Manager index @mgfryan
Please resolve the error(s) mentioned in the previous comment.

After resolving the issue, trigger this check again by doing one of the following:

  • Commit the required change to the branch you submitted this pull request from.
  • Comment here, mentioning @ArduinoBot in the comment.

NOTE: It is not necessary to open a new pull request. ❗

More information:
https://github.com/arduino/library-registry/blob/main/README.md#if-the-problem-is-with-the-pull-request

@mgfryan
Copy link
Contributor Author

mgfryan commented Feb 16, 2025

@ArduinoBot: Added tag!

Copy link
Contributor

Hello! I'm checking your submission again.

@github-actions github-actions bot merged commit 803eb79 into arduino:main Feb 16, 2025
14 checks passed
Copy link
Contributor

Your submission has now been accepted! Thanks for your contribution to the Arduino Library Manager index.

The library(s) will be available for installation via Library Manager within a day's time.

You can check the logs from the Library Manager indexer for your library(s) here:
http://downloads.arduino.cc/libraries/logs/bitbucket.org/mgf_ryan/smartsystem/

github-actions bot pushed a commit that referenced this pull request Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: submission Add library to the list
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant