Code Contribution Guidelines

created by hek , updated by blacey

Contributing Code

The MySensors project is open and welcomes new code contributors. If you plan to make a large refactoring or massive changes, please create an issue first to allow collaborate and provide feedback before submitting a GitHub pull request.. We wouldn't want you to spend a lot of time on something that wouldn't make it into the project.

Fetching the MySensors repository from GitHub

The normal workflow is that you create a fork of the MySensors repository by visiting . Press the "Fork" button found here:

Now it's time to download the forked repository to your computer.

We recommend installing the git command line tool. It's available for all types of platforms.

To fetch the repository from github, run the following command in your terminal window:

# Clone your forked repository to your computer.
> git clone<your username>/MySensors.git

# Change directory to your newly cloned repository
> cd MySensors

# Check out the development branch
MySensors> git checkout development

# Configure your repo for MySensors development (this ensures that you have everything you need to submit a PR)
MySensors> .mystools/

NOTE: If bootstrap-dev prompts you to install required tools, follow the Installation instructions for prerequisite Tools and the re-run .mystools/ to complete your repo setup.

Make sure to change your username if prompted above. GitHub also provides Instructions for setting you email address/username

Now you are ready to use your favourite editor or IDE to make the patch and/or enhancement. Fix all warnings when building or the PR won't be accepted otherwise.

When you are ready to submit a PR, make a habit of fetching the latest changes from the upstream repo before committing.

# Fetch upstream changes
MySensors> git fetch upstream
# Merges upstream changes into your local branch
MySensors> git merge upstream/development

# Stage file(s) to for commit to your local repository. Repeat the add command for each changed file or folder you want to commit.
MySensors> git add <file or directory>
# Limit commmit message subject to 50 characters. See "keep a tidy git log" below.
MySensors> git commit -m "Your commmit message"
# Push changes to yor github repository
MySensors> git push

Now you are ready to create a pull request on Go to your cloned repository and press "New Pull Request":

Enter your description for the pull request and create it.

Our build server will run tests on each pull request. It will check the following before accepting it.

  1. Validity of commit message. Keep subject below 50 chars. Body below 70 chars.
  2. Codestyle. See Coding Guidelines below.
  3. No build errors or warnings. We run a series of test builds for different platforms (AVR, ESP8266, SAMD, Linux/RPI). Save yourself a lot of troubles by eliminating warnings before pushing PR.
  4. Signed Contributor License Agreement (CLA). You can sign it here.

Note! We only accept pull requests on the development branch. Master is only used for releases.

Commit Messages - Keep a tidy git log

We'd like to keep the commit log readable, relevant and tidy. We highly recommend you to read this article on the subject.

You can find the current MySenosrs development git log here to get an idea of what a good commit message should look like:

Amending Git Messages or PRs

If your PR gets rejected or if you want to make additions. Amending is the way to go. Followed by a force push. Github will update the PR automatically and our build server will try again.

Rebasing an out-of-date PR

enter image description here

If changes are introduced to the development branch that conflicts with an open PR, the PR might not be possible to merge. You will have to resolve the conflicts and update the PR.

# Fetch upstream changes
MySensors> git fetch upstream
# Merges upstream changes into your local branch
MySensors> git checkout development
MySensors> git merge upstream/development

# Rebase the branch you filed the PR from against your updated development branch
MySensors> git checkout <yourbranch>
MySensors> git rebase development
# You can expect merge conflicts to occur here, which you will need to resolve, add and commit.
# ...
# Force push your updated branch so the PR gets updated
MySensors> git push HEAD:<yourbranch> -f

Signing CLA

To accept contributions to the MySensors core library, you have to sign our contributor license agreement found here:

This is not needed, if you just want to add a new example in the examples repository:

Coding Guidelines (core library)

Artistic style can be used to verify coding standard and the repository holds a rules definition file at '.astylerc' which can be used to get the rules below verified by the tool. We also offer a git-commit hook to verify the coding structure of the commit in question. It can be installed using 'hooks/' and works on Linux, MacOS and Windows (cygwin/bash based shells).

  • We use camelCase for function and variable names.
  • Tab-character for white space/indentation.
  • All control statements ('if', 'for', 'while' etc.) should include curly braces {}. Even one-liners.
  • Curly braces should follow "One True Brace Style" format like this:

    void myFunction()
      int i;
      for (i = 0; i < 42; i++) {
          if (0 == i) {
  • All new code should include documentation in doxygen. See an example here.

  • Avoid using Systems Hungarian notation:
    bool bDone;
    int iCnt;
  • All lines should be kept at 100 character width or less
    • When breaking logical conditionals, keep the conditionals on the first line like this:
      if (thisVariable1 == thatVariable1 ||
          thisVariable2 == thatVariable2 ||
          thisVariable3 == thatVariable3)
  • Preprocessor definitions should be indented if linebroken:
    #define Is_Bar(arg,a,b) \
      (Is_Foo((arg), (a)) \
       || Is_Foo((arg), (b)))
  • Preprocessor conditions should NOT be indented to source level, but be kept in first column:
    #ifdef UNICODE
          text = wideBuff;
          text = buff;
  • C++ comments should be indented to source level, and not be kept in first column:
    void Foo()
      // comment
      if (isFoo) {
  • Source files should be stored in UTF-8 encoding with LF/"Unix" style line endings

Related Content