particle-commands 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
4
4
  and this project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ### 0.5.0 - 2023-10-10
7
+ - Add the new Particle project template
8
+
9
+ ### 0.4.1-rc.0 - 2023-09-26
10
+ - [tests] add project directory
11
+
6
12
  ### 0.4.0 - 2022-05-31
7
13
  - Move to `node@16` and `npm@8` for local development
8
14
 
@@ -294,22 +294,29 @@ var ProjectInitCommand = exports.ProjectInitCommand = function (_Command) {
294
294
  var _this6 = this;
295
295
 
296
296
  var properties = { name: name };
297
- var projectFile = _path2.default.join(directory, 'project.properties');
298
297
  var project = new _project_properties2.default(directory, { fs: _project_properties2.default.buildFs(fs) });
299
298
  return this.createNotifyDirectory(site, fs, directory).then(function () {
299
+ return _this6.createNotifyTemplateIfNeeded(site, fs, _path2.default.join(directory, '.gitignore'), '.gitignore', properties);
300
+ }).then(function () {
301
+ return _this6.createNotifyFileIfNeeded(site, fs, _path2.default.join(directory, 'project.properties'), '');
302
+ }).then(function () {
300
303
  return _this6.createNotifyDirectory(site, fs, _path2.default.join(directory, 'src'));
301
304
  }).then(function () {
302
- return _this6.createNotifyFileIfNeeded(site, fs, projectFile, '');
305
+ return _this6.createNotifyDirectory(site, fs, _path2.default.join(directory, '.github', 'workflows'));
306
+ }).then(function () {
307
+ return _this6.createNotifyTemplateIfNeeded(site, fs, _path2.default.join(directory, '.github', 'workflows', 'main.yaml'), '.github/workflows/main.yaml', properties);
303
308
  }).then(function () {
304
309
  return _this6.createNotifyTemplateIfNeeded(site, fs, _path2.default.join(directory, 'README.md'), 'README.md', properties);
305
310
  }).then(function () {
306
- return _this6.createNotifyTemplateIfNeeded(site, fs, _path2.default.join(directory, 'src', name + '.ino'), 'project.ino', properties);
311
+ return _this6.createNotifyTemplateIfNeeded(site, fs, _path2.default.join(directory, 'src', name + '.cpp'), 'src/project.cpp', properties);
307
312
  }).then(function () {
308
313
  return project.load();
309
314
  }).then(function () {
310
315
  if (project.setField('name', name)) {
311
316
  return project.save();
312
317
  }
318
+ }).then(function () {
319
+ return project.writeAssetOtaDir();
313
320
  });
314
321
  }
315
322
 
@@ -33,7 +33,7 @@ function buildPromisefs() {
33
33
  var fs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _fs2.default;
34
34
 
35
35
  var promisefs = {};
36
- ['readFile', 'writeFile', 'stat'].forEach(function (fn) {
36
+ ['readFile', 'writeFile', 'appendFile', 'stat'].forEach(function (fn) {
37
37
  return promisefs[fn] = (0, _es6Promisify2.default)(fs[fn]);
38
38
  });
39
39
  return promisefs;
@@ -120,6 +120,13 @@ var ProjectProperties = function () {
120
120
  var data = this.serialize();
121
121
  return this.fs.writeFile(this.name(), data, 'utf8');
122
122
  }
123
+ }, {
124
+ key: 'writeAssetOtaDir',
125
+ value: function writeAssetOtaDir() {
126
+ // Add a commented line for assetOtaDir
127
+ var data = '#assetOtaDir=assets\n';
128
+ return this.fs.appendFile(this.name(), data, 'utf8');
129
+ }
123
130
  }, {
124
131
  key: 'serialize',
125
132
  value: function serialize() {
@@ -0,0 +1,37 @@
1
+ # Particle Compile Action Workflow
2
+ # This workflow uses the Particle compile-action to compile Particle application firmware.
3
+ # Make sure to set the particle-platform-name for your project.
4
+ # For complete documentation, please refer to https://github.com/particle-iot/compile-action
5
+
6
+ name: Particle Compile
7
+
8
+ on:
9
+ push:
10
+ branches:
11
+ - main
12
+
13
+ jobs:
14
+ compile:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ # Particle Compile Action
22
+ - name: Compile Firmware
23
+ id: compile
24
+ uses: particle-iot/compile-action@v1
25
+ with:
26
+ # Set the particle-platform-name to the platform you're targeting.
27
+ # Allowed values: core, photon, p1, electron, argon, boron, xenon, esomx, bsom, b5som, tracker, trackerm, p2, msom
28
+ particle-platform-name: 'p2'
29
+
30
+ # Optional: Upload compiled firmware as an artifact on GitHub.
31
+ - name: Upload Firmware as Artifact
32
+ uses: actions/upload-artifact@v3
33
+ with:
34
+ name: firmware-artifact
35
+ path: |
36
+ ${{ steps.compile.outputs.firmware-path }}
37
+ ${{ steps.compile.outputs.target-path }}
@@ -1,35 +1,100 @@
1
1
  # <%=name%>
2
2
 
3
- A Particle project named <%=name%>
3
+ This firmware project was created using [Particle Developer Tools](https://www.particle.io/developer-tools/) and is compatible with all [Particle Devices](https://www.particle.io/devices/).
4
4
 
5
- ## Welcome to your project!
5
+ Feel free to replace this README.md file with your own content, or keep it for reference.
6
6
 
7
- Every new Particle project is composed of 3 important elements that you'll see have been created in your project directory for <%=name%>.
7
+ ## Table of Contents
8
+ - [Introduction](#introduction)
9
+ - [Prerequisites To Use This Template](#prerequisites-to-use-this-repository)
10
+ - [Getting Started](#getting-started)
11
+ - [Particle Firmware At A Glance](#particle-firmware-at-a-glance)
12
+ - [Logging](#logging)
13
+ - [Setup and Loop](#setup-and-loop)
14
+ - [Delays and Timing](#delays-and-timing)
15
+ - [Testing and Debugging](#testing-and-debugging)
16
+ - [GitHub Actions (CI/CD)](#github-actions-cicd)
17
+ - [OTA](#ota)
18
+ - [Support and Feedback](#support-and-feedback)
19
+ - [Version](#version)
8
20
 
9
- #### ```/src``` folder:
10
- This is the source folder that contains the firmware files for your project. It should *not* be renamed.
11
- Anything that is in this folder when you compile your project will be sent to our compile service and compiled into a firmware binary for the Particle device that you have targeted.
21
+ ## Introduction
12
22
 
13
- If your application contains multiple files, they should all be included in the `src` folder. If your firmware depends on Particle libraries, those dependencies are specified in the `project.properties` file referenced below.
23
+ For an in-depth understanding of this project template, please refer to our [documentation](https://docs.particle.io/firmware/best-practices/firmware-template/).
14
24
 
15
- #### ```.ino``` file:
16
- This file is the firmware that will run as the primary application on your Particle device. It contains a `setup()` and `loop()` function, and can be written in Wiring or C/C++. For more information about using the Particle firmware API to create firmware for your Particle device, refer to the [Firmware Reference](https://docs.particle.io/reference/firmware/) section of the Particle documentation.
25
+ ## Prerequisites To Use This Repository
17
26
 
18
- #### ```project.properties``` file:
19
- This is the file that specifies the name and version number of the libraries that your project depends on. Dependencies are added automatically to your `project.properties` file when you add a library to a project using the `particle library add` command in the CLI or add a library in the Desktop IDE.
27
+ To use this software/firmware on a device, you'll need:
20
28
 
21
- ## Adding additional files to your project
29
+ - A [Particle Device](https://www.particle.io/devices/).
30
+ - Windows/Mac/Linux for building the software and flashing it to a device.
31
+ - [Particle Development Tools](https://docs.particle.io/getting-started/developer-tools/developer-tools/) installed and set up on your computer.
32
+ - Optionally, a nice cup of tea (and perhaps a biscuit).
22
33
 
23
- #### Projects with multiple sources
24
- If you would like add additional files to your application, they should be added to the `/src` folder. All files in the `/src` folder will be sent to the Particle Cloud to produce a compiled binary.
34
+ ## Getting Started
25
35
 
26
- #### Projects with external libraries
27
- If your project includes a library that has not been registered in the Particle libraries system, you should create a new folder named `/lib/<libraryname>/src` under `/<project dir>` and add the `.h`, `.cpp` & `library.properties` files for your library there. Read the [Firmware Libraries guide](https://docs.particle.io/guide/tools-and-features/libraries/) for more details on how to develop libraries. Note that all contents of the `/lib` folder and subfolders will also be sent to the Cloud for compilation.
36
+ 1. While not essential, we recommend running the [device setup process](https://setup.particle.io/) on your Particle device first. This ensures your device's firmware is up-to-date and you have a solid baseline to start from.
28
37
 
29
- ## Compiling your project
38
+ 2. If you haven't already, open this project in Visual Studio Code (File -> Open Folder). Then [compile and flash](https://docs.particle.io/getting-started/developer-tools/workbench/#cloud-build-and-flash) your device. Ensure your device's USB port is connected to your computer.
30
39
 
31
- When you're ready to compile your project, make sure you have the correct Particle device target selected and run `particle compile <platform>` in the CLI or click the Compile button in the Desktop IDE. The following files in your project folder will be sent to the compile service:
40
+ 3. Verify the device's operation by monitoring its logging output:
41
+ - In Visual Studio Code with the Particle Plugin, open the [command palette](https://docs.particle.io/getting-started/developer-tools/workbench/#particle-commands) and choose "Particle: Serial Monitor".
42
+ - Or, using the Particle CLI, execute:
43
+ ```
44
+ particle serial monitor --follow
45
+ ```
32
46
 
33
- - Everything in the `/src` folder, including your `.ino` application file
34
- - The `project.properties` file for your project
35
- - Any libraries stored under `lib/<libraryname>/src`
47
+ 4. Uncomment the code at the bottom of the cpp file in your src directory to publish to the Particle Cloud! Login to console.particle.io to view your devices events in real time.
48
+
49
+ 5. Customize this project! For firmware details, see [Particle firmware](https://docs.particle.io/reference/device-os/api/introduction/getting-started/). For information on the project's directory structure, visit [this link](https://docs.particle.io/firmware/best-practices/firmware-template/#project-overview).
50
+
51
+ ## Particle Firmware At A Glance
52
+
53
+ ### Logging
54
+
55
+ The firmware includes a [logging library](https://docs.particle.io/reference/device-os/api/logging/logger-class/). You can display messages at different levels and filter them:
56
+
57
+ ```
58
+ Log.trace("This is trace message");
59
+ Log.info("This is info message");
60
+ Log.warn("This is warn message");
61
+ Log.error("This is error message");
62
+ ```
63
+
64
+ ### Setup and Loop
65
+
66
+ Particle projects originate from the Wiring/Processing framework, which is based on C++. Typically, one-time setup functions are placed in `setup()`, and the main application runs from the `loop()` function.
67
+
68
+ For advanced scenarios, explore our [threading support](https://docs.particle.io/firmware/software-design/threading-explainer/).
69
+
70
+ ### Delays and Timing
71
+
72
+ By default, the setup() and loop() functions are blocking whilst they run, meaning that if you put in a delay, your entire application will wait for that delay to finish before anything else can run.
73
+
74
+ For techniques that allow you to run multiple tasks in parallel without creating threads, checkout the code example [here](https://docs.particle.io/firmware/best-practices/firmware-template/).
75
+
76
+ (Note: Although using `delay()` isn't recommended for best practices, it's acceptable for testing.)
77
+
78
+ ### Testing and Debugging
79
+
80
+ For firmware testing and debugging guidance, check [this documentation](https://docs.particle.io/troubleshooting/guides/build-tools-troubleshooting/debugging-firmware-builds/).
81
+
82
+ ### GitHub Actions (CI/CD)
83
+
84
+ This project provides a YAML file for GitHub, automating firmware compilation whenever changes are pushed. More details on [Particle GitHub Actions](https://docs.particle.io/firmware/best-practices/github-actions/) are available.
85
+
86
+ ### OTA
87
+
88
+ To learn how to utilize Particle's OTA service for device updates, consult [this documentation](https://docs.particle.io/getting-started/cloud/ota-updates/).
89
+
90
+ Test OTA with the 'Particle: Cloud Flash' command in Visual Studio Code or the CLI command 'particle flash'!
91
+
92
+ This firmware supports binary assets in OTA packages, allowing the inclusion of audio, images, configurations, and external microcontroller firmware. More details are [here](https://docs.particle.io/reference/device-os/api/asset-ota/asset-ota/).
93
+
94
+ ## Support and Feedback
95
+
96
+ For support or feedback on this template or any Particle products, please join our [community](https://community.particle.io)!
97
+
98
+ ## Version
99
+
100
+ Template version 1.0.2
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Project myProject
3
+ * Author: Your Name
4
+ * Date:
5
+ * For comprehensive documentation and examples, please visit:
6
+ * https://docs.particle.io/firmware/best-practices/firmware-template/
7
+ */
8
+
9
+ // Include Particle Device OS APIs
10
+ #include "Particle.h"
11
+
12
+ // Let Device OS manage the connection to the Particle Cloud
13
+ SYSTEM_MODE(AUTOMATIC);
14
+
15
+ // Run the application and system concurrently in separate threads
16
+ SYSTEM_THREAD(ENABLED);
17
+
18
+ // Show system, cloud connectivity, and application logs over USB
19
+ // View logs with CLI using 'particle serial monitor --follow'
20
+ SerialLogHandler logHandler(LOG_LEVEL_INFO);
21
+
22
+ // setup() runs once, when the device is first turned on
23
+ void setup() {
24
+ // Put initialization like pinMode and begin functions here
25
+ }
26
+
27
+ // loop() runs over and over again, as quickly as it can execute.
28
+ void loop() {
29
+ // The core of your code will likely live here.
30
+
31
+ // Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
32
+ // Logging.info("Sending Hello World to the cloud!");
33
+ // Particle.publish("Hello world!");
34
+ // delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!
35
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "particle-commands",
3
3
  "description": "Library of UX-neutral commands that provide key functionality for developer tools",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "author": "Matthew McGowan",
6
6
  "bugs": {
7
7
  "url": "https://github.com/particle-iot/particle-commands/issues"
@@ -35,6 +35,7 @@
35
35
  "babel-register": "^6.5.2",
36
36
  "chai": "^3.5.0",
37
37
  "chai-as-promised": "^5.3.0",
38
+ "copyfiles": "^2.4.1",
38
39
  "coveralls": "^2.11.4",
39
40
  "doctoc": "^0.15.0",
40
41
  "eslint": "~2.2.0",
@@ -73,7 +74,9 @@
73
74
  "prepublish": "npm run compile",
74
75
  "preversion": "npm run lint && npm run test && npm run prepublish",
75
76
  "version": "npm run update-changelog",
76
- "compile": "babel src -d dist --copy-files",
77
+ "compile": "npm run compile:src && npm run copy:dotfiles",
78
+ "compile:src": "babel src -d dist --copy-files",
79
+ "copy:dotfiles": "copyfiles -u 4 src/cmd/templates/project/.github/**/* src/cmd/templates/project/.gitignore dist/cmd/templates/project/",
77
80
  "babel-watch": "babel src -d dist --watch --source-maps --copy-files",
78
81
  "doctoc": "doctoc --title '## Table of Contents' README.md",
79
82
  "list-folders": "node --require babel-register bin/list_folders.js",
@@ -208,19 +208,22 @@ export class ProjectInitCommand extends Command {
208
208
 
209
209
  createProject(site, fs, directory, name) {
210
210
  const properties = { name };
211
- const projectFile = path.join(directory, 'project.properties');
212
211
  const project = new ProjectProperties(directory, { fs:ProjectProperties.buildFs(fs) });
213
212
  return this.createNotifyDirectory(site, fs, directory)
213
+ .then(() => this.createNotifyTemplateIfNeeded(site, fs, path.join(directory, '.gitignore'), '.gitignore', properties))
214
+ .then(() => this.createNotifyFileIfNeeded(site, fs, path.join(directory, 'project.properties'), ''))
214
215
  .then(() => this.createNotifyDirectory(site, fs, path.join(directory, 'src')))
215
- .then(() => this.createNotifyFileIfNeeded(site, fs, projectFile, ''))
216
+ .then(() => this.createNotifyDirectory(site, fs, path.join(directory, '.github', 'workflows')))
217
+ .then(() => this.createNotifyTemplateIfNeeded(site, fs, path.join(directory, '.github', 'workflows', 'main.yaml'), '.github/workflows/main.yaml', properties))
216
218
  .then(() => this.createNotifyTemplateIfNeeded(site, fs, path.join(directory, 'README.md'), 'README.md', properties))
217
- .then(() => this.createNotifyTemplateIfNeeded(site, fs, path.join(directory, 'src', name+'.ino'), 'project.ino', properties))
219
+ .then(() => this.createNotifyTemplateIfNeeded(site, fs, path.join(directory, 'src', name + '.cpp'), 'src/project.cpp', properties))
218
220
  .then(() => project.load())
219
221
  .then(() => {
220
222
  if (project.setField('name', name)) {
221
223
  return project.save();
222
224
  }
223
- });
225
+ })
226
+ .then(() => project.writeAssetOtaDir());
224
227
  }
225
228
 
226
229
  /**
@@ -10,6 +10,7 @@ function buildPromisefs(fs=nodeFs) {
10
10
  [
11
11
  'readFile',
12
12
  'writeFile',
13
+ 'appendFile',
13
14
  'stat'
14
15
  ].forEach(fn => promisefs[fn] = promisify(fs[fn]));
15
16
  return promisefs;
@@ -71,6 +72,12 @@ export default class ProjectProperties {
71
72
  return this.fs.writeFile(this.name(), data, 'utf8');
72
73
  }
73
74
 
75
+ writeAssetOtaDir() {
76
+ // Add a commented line for assetOtaDir
77
+ const data = '#assetOtaDir=assets\n';
78
+ return this.fs.appendFile(this.name(), data, 'utf8');
79
+ }
80
+
74
81
  serialize() {
75
82
  return Object.keys(this.fields).map(field => {
76
83
  return `${field}=${this.fields[field]}`;
@@ -0,0 +1,37 @@
1
+ # Particle Compile Action Workflow
2
+ # This workflow uses the Particle compile-action to compile Particle application firmware.
3
+ # Make sure to set the particle-platform-name for your project.
4
+ # For complete documentation, please refer to https://github.com/particle-iot/compile-action
5
+
6
+ name: Particle Compile
7
+
8
+ on:
9
+ push:
10
+ branches:
11
+ - main
12
+
13
+ jobs:
14
+ compile:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ # Particle Compile Action
22
+ - name: Compile Firmware
23
+ id: compile
24
+ uses: particle-iot/compile-action@v1
25
+ with:
26
+ # Set the particle-platform-name to the platform you're targeting.
27
+ # Allowed values: core, photon, p1, electron, argon, boron, xenon, esomx, bsom, b5som, tracker, trackerm, p2, msom
28
+ particle-platform-name: 'p2'
29
+
30
+ # Optional: Upload compiled firmware as an artifact on GitHub.
31
+ - name: Upload Firmware as Artifact
32
+ uses: actions/upload-artifact@v3
33
+ with:
34
+ name: firmware-artifact
35
+ path: |
36
+ ${{ steps.compile.outputs.firmware-path }}
37
+ ${{ steps.compile.outputs.target-path }}
@@ -1,35 +1,100 @@
1
1
  # <%=name%>
2
2
 
3
- A Particle project named <%=name%>
3
+ This firmware project was created using [Particle Developer Tools](https://www.particle.io/developer-tools/) and is compatible with all [Particle Devices](https://www.particle.io/devices/).
4
4
 
5
- ## Welcome to your project!
5
+ Feel free to replace this README.md file with your own content, or keep it for reference.
6
6
 
7
- Every new Particle project is composed of 3 important elements that you'll see have been created in your project directory for <%=name%>.
7
+ ## Table of Contents
8
+ - [Introduction](#introduction)
9
+ - [Prerequisites To Use This Template](#prerequisites-to-use-this-repository)
10
+ - [Getting Started](#getting-started)
11
+ - [Particle Firmware At A Glance](#particle-firmware-at-a-glance)
12
+ - [Logging](#logging)
13
+ - [Setup and Loop](#setup-and-loop)
14
+ - [Delays and Timing](#delays-and-timing)
15
+ - [Testing and Debugging](#testing-and-debugging)
16
+ - [GitHub Actions (CI/CD)](#github-actions-cicd)
17
+ - [OTA](#ota)
18
+ - [Support and Feedback](#support-and-feedback)
19
+ - [Version](#version)
8
20
 
9
- #### ```/src``` folder:
10
- This is the source folder that contains the firmware files for your project. It should *not* be renamed.
11
- Anything that is in this folder when you compile your project will be sent to our compile service and compiled into a firmware binary for the Particle device that you have targeted.
21
+ ## Introduction
12
22
 
13
- If your application contains multiple files, they should all be included in the `src` folder. If your firmware depends on Particle libraries, those dependencies are specified in the `project.properties` file referenced below.
23
+ For an in-depth understanding of this project template, please refer to our [documentation](https://docs.particle.io/firmware/best-practices/firmware-template/).
14
24
 
15
- #### ```.ino``` file:
16
- This file is the firmware that will run as the primary application on your Particle device. It contains a `setup()` and `loop()` function, and can be written in Wiring or C/C++. For more information about using the Particle firmware API to create firmware for your Particle device, refer to the [Firmware Reference](https://docs.particle.io/reference/firmware/) section of the Particle documentation.
25
+ ## Prerequisites To Use This Repository
17
26
 
18
- #### ```project.properties``` file:
19
- This is the file that specifies the name and version number of the libraries that your project depends on. Dependencies are added automatically to your `project.properties` file when you add a library to a project using the `particle library add` command in the CLI or add a library in the Desktop IDE.
27
+ To use this software/firmware on a device, you'll need:
20
28
 
21
- ## Adding additional files to your project
29
+ - A [Particle Device](https://www.particle.io/devices/).
30
+ - Windows/Mac/Linux for building the software and flashing it to a device.
31
+ - [Particle Development Tools](https://docs.particle.io/getting-started/developer-tools/developer-tools/) installed and set up on your computer.
32
+ - Optionally, a nice cup of tea (and perhaps a biscuit).
22
33
 
23
- #### Projects with multiple sources
24
- If you would like add additional files to your application, they should be added to the `/src` folder. All files in the `/src` folder will be sent to the Particle Cloud to produce a compiled binary.
34
+ ## Getting Started
25
35
 
26
- #### Projects with external libraries
27
- If your project includes a library that has not been registered in the Particle libraries system, you should create a new folder named `/lib/<libraryname>/src` under `/<project dir>` and add the `.h`, `.cpp` & `library.properties` files for your library there. Read the [Firmware Libraries guide](https://docs.particle.io/guide/tools-and-features/libraries/) for more details on how to develop libraries. Note that all contents of the `/lib` folder and subfolders will also be sent to the Cloud for compilation.
36
+ 1. While not essential, we recommend running the [device setup process](https://setup.particle.io/) on your Particle device first. This ensures your device's firmware is up-to-date and you have a solid baseline to start from.
28
37
 
29
- ## Compiling your project
38
+ 2. If you haven't already, open this project in Visual Studio Code (File -> Open Folder). Then [compile and flash](https://docs.particle.io/getting-started/developer-tools/workbench/#cloud-build-and-flash) your device. Ensure your device's USB port is connected to your computer.
30
39
 
31
- When you're ready to compile your project, make sure you have the correct Particle device target selected and run `particle compile <platform>` in the CLI or click the Compile button in the Desktop IDE. The following files in your project folder will be sent to the compile service:
40
+ 3. Verify the device's operation by monitoring its logging output:
41
+ - In Visual Studio Code with the Particle Plugin, open the [command palette](https://docs.particle.io/getting-started/developer-tools/workbench/#particle-commands) and choose "Particle: Serial Monitor".
42
+ - Or, using the Particle CLI, execute:
43
+ ```
44
+ particle serial monitor --follow
45
+ ```
32
46
 
33
- - Everything in the `/src` folder, including your `.ino` application file
34
- - The `project.properties` file for your project
35
- - Any libraries stored under `lib/<libraryname>/src`
47
+ 4. Uncomment the code at the bottom of the cpp file in your src directory to publish to the Particle Cloud! Login to console.particle.io to view your devices events in real time.
48
+
49
+ 5. Customize this project! For firmware details, see [Particle firmware](https://docs.particle.io/reference/device-os/api/introduction/getting-started/). For information on the project's directory structure, visit [this link](https://docs.particle.io/firmware/best-practices/firmware-template/#project-overview).
50
+
51
+ ## Particle Firmware At A Glance
52
+
53
+ ### Logging
54
+
55
+ The firmware includes a [logging library](https://docs.particle.io/reference/device-os/api/logging/logger-class/). You can display messages at different levels and filter them:
56
+
57
+ ```
58
+ Log.trace("This is trace message");
59
+ Log.info("This is info message");
60
+ Log.warn("This is warn message");
61
+ Log.error("This is error message");
62
+ ```
63
+
64
+ ### Setup and Loop
65
+
66
+ Particle projects originate from the Wiring/Processing framework, which is based on C++. Typically, one-time setup functions are placed in `setup()`, and the main application runs from the `loop()` function.
67
+
68
+ For advanced scenarios, explore our [threading support](https://docs.particle.io/firmware/software-design/threading-explainer/).
69
+
70
+ ### Delays and Timing
71
+
72
+ By default, the setup() and loop() functions are blocking whilst they run, meaning that if you put in a delay, your entire application will wait for that delay to finish before anything else can run.
73
+
74
+ For techniques that allow you to run multiple tasks in parallel without creating threads, checkout the code example [here](https://docs.particle.io/firmware/best-practices/firmware-template/).
75
+
76
+ (Note: Although using `delay()` isn't recommended for best practices, it's acceptable for testing.)
77
+
78
+ ### Testing and Debugging
79
+
80
+ For firmware testing and debugging guidance, check [this documentation](https://docs.particle.io/troubleshooting/guides/build-tools-troubleshooting/debugging-firmware-builds/).
81
+
82
+ ### GitHub Actions (CI/CD)
83
+
84
+ This project provides a YAML file for GitHub, automating firmware compilation whenever changes are pushed. More details on [Particle GitHub Actions](https://docs.particle.io/firmware/best-practices/github-actions/) are available.
85
+
86
+ ### OTA
87
+
88
+ To learn how to utilize Particle's OTA service for device updates, consult [this documentation](https://docs.particle.io/getting-started/cloud/ota-updates/).
89
+
90
+ Test OTA with the 'Particle: Cloud Flash' command in Visual Studio Code or the CLI command 'particle flash'!
91
+
92
+ This firmware supports binary assets in OTA packages, allowing the inclusion of audio, images, configurations, and external microcontroller firmware. More details are [here](https://docs.particle.io/reference/device-os/api/asset-ota/asset-ota/).
93
+
94
+ ## Support and Feedback
95
+
96
+ For support or feedback on this template or any Particle products, please join our [community](https://community.particle.io)!
97
+
98
+ ## Version
99
+
100
+ Template version 1.0.2
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Project myProject
3
+ * Author: Your Name
4
+ * Date:
5
+ * For comprehensive documentation and examples, please visit:
6
+ * https://docs.particle.io/firmware/best-practices/firmware-template/
7
+ */
8
+
9
+ // Include Particle Device OS APIs
10
+ #include "Particle.h"
11
+
12
+ // Let Device OS manage the connection to the Particle Cloud
13
+ SYSTEM_MODE(AUTOMATIC);
14
+
15
+ // Run the application and system concurrently in separate threads
16
+ SYSTEM_THREAD(ENABLED);
17
+
18
+ // Show system, cloud connectivity, and application logs over USB
19
+ // View logs with CLI using 'particle serial monitor --follow'
20
+ SerialLogHandler logHandler(LOG_LEVEL_INFO);
21
+
22
+ // setup() runs once, when the device is first turned on
23
+ void setup() {
24
+ // Put initialization like pinMode and begin functions here
25
+ }
26
+
27
+ // loop() runs over and over again, as quickly as it can execute.
28
+ void loop() {
29
+ // The core of your code will likely live here.
30
+
31
+ // Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
32
+ // Logging.info("Sending Hello World to the cloud!");
33
+ // Particle.publish("Hello world!");
34
+ // delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!
35
+ }
@@ -28,7 +28,7 @@ describe('LibraryPublishCommand', () => {
28
28
  }
29
29
  };
30
30
 
31
- const execute = () => sut.run({user: {id: 'foo'}, api: {key: 'bar'}}, site);
31
+ const execute = () => sut.run({ user: { id: 'foo' }, api: { key: 'bar' } }, site);
32
32
 
33
33
  const verify = () => {
34
34
  throw new Error('expected rejection');
@@ -16,8 +16,10 @@ describe('project_init', () => {
16
16
 
17
17
  beforeEach(() => {
18
18
  const fs = {};
19
+ addFile(fs, ProjectInitCommand.templateFile('.gitignore'));
19
20
  addFile(fs, ProjectInitCommand.templateFile('README.md'));
20
- addFile(fs, ProjectInitCommand.templateFile('project.ino'));
21
+ addFile(fs, ProjectInitCommand.templateFile('src/project.cpp'));
22
+ addFile(fs, ProjectInitCommand.templateFile('.github/workflows/main.yaml'));
21
23
  mockfs(fs);
22
24
  });
23
25
 
@@ -49,8 +51,10 @@ describe('project_init', () => {
49
51
  expect(fs.existsSync(directory), 'expected project directory to exist').to.be.true;
50
52
  expect(fs.existsSync(path.join(directory, 'src')), 'expected src directory to exist').to.be.true;
51
53
  expect(fs.existsSync(path.join(directory, 'project.properties')), 'expected project.properties to exist').to.be.true;
54
+ expectTemplate(path.join(directory, '.gitignore'), '.gitignore', properties);
55
+ expectTemplate(path.join(directory, '.github', 'workflows', 'main.yaml'), '.github/workflows/main.yaml', properties);
52
56
  expectTemplate(path.join(directory, 'README.md'), 'README.md', properties);
53
- expectTemplate(path.join(directory, 'src', properties.name+'.ino'), 'project.ino', properties);
57
+ expectTemplate(path.join(directory, 'src', properties.name+'.cpp'), 'src/project.cpp', properties);
54
58
 
55
59
  const project = new ProjectProperties(directory, { fs:ProjectProperties.buildFs(fs) });
56
60
  return project.load()
@@ -0,0 +1 @@
1
+ TBD
@@ -0,0 +1 @@
1
+ name=basic
@@ -0,0 +1,37 @@
1
+ # Particle Compile Action Workflow
2
+ # This workflow uses the Particle compile-action to compile Particle application firmware.
3
+ # Make sure to set the particle-platform-name for your project.
4
+ # For complete documentation, please refer to https://github.com/particle-iot/compile-action
5
+
6
+ name: Particle Compile
7
+
8
+ on:
9
+ push:
10
+ branches:
11
+ - main
12
+
13
+ jobs:
14
+ compile:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ # Particle Compile Action
22
+ - name: Compile Firmware
23
+ id: compile
24
+ uses: particle-iot/compile-action@v1
25
+ with:
26
+ # Set the particle-platform-name to the platform you're targeting.
27
+ # Allowed values: core, photon, p1, electron, argon, boron, xenon, esomx, bsom, b5som, tracker, trackerm, p2, msom
28
+ particle-platform-name: 'p2'
29
+
30
+ # Optional: Upload compiled firmware as an artifact on GitHub.
31
+ - name: Upload Firmware as Artifact
32
+ uses: actions/upload-artifact@v3
33
+ with:
34
+ name: firmware-artifact
35
+ path: |
36
+ ${{ steps.compile.outputs.firmware-path }}
37
+ ${{ steps.compile.outputs.target-path }}
@@ -0,0 +1,100 @@
1
+ # myProject
2
+
3
+ This firmware project was created using [Particle Developer Tools](https://www.particle.io/developer-tools/) and is compatible with all [Particle Devices](https://www.particle.io/devices/).
4
+
5
+ Feel free to replace this README.md file with your own content, or keep it for reference.
6
+
7
+ ## Table of Contents
8
+ - [Introduction](#introduction)
9
+ - [Prerequisites To Use This Template](#prerequisites-to-use-this-repository)
10
+ - [Getting Started](#getting-started)
11
+ - [Particle Firmware At A Glance](#particle-firmware-at-a-glance)
12
+ - [Logging](#logging)
13
+ - [Setup and Loop](#setup-and-loop)
14
+ - [Delays and Timing](#delays-and-timing)
15
+ - [Testing and Debugging](#testing-and-debugging)
16
+ - [GitHub Actions (CI/CD)](#github-actions-cicd)
17
+ - [OTA](#ota)
18
+ - [Support and Feedback](#support-and-feedback)
19
+ - [Version](#version)
20
+
21
+ ## Introduction
22
+
23
+ For an in-depth understanding of this project template, please refer to our [documentation](https://docs.particle.io/firmware/best-practices/firmware-template/).
24
+
25
+ ## Prerequisites To Use This Repository
26
+
27
+ To use this software/firmware on a device, you'll need:
28
+
29
+ - A [Particle Device](https://www.particle.io/devices/).
30
+ - Windows/Mac/Linux for building the software and flashing it to a device.
31
+ - [Particle Development Tools](https://docs.particle.io/getting-started/developer-tools/developer-tools/) installed and set up on your computer.
32
+ - Optionally, a nice cup of tea (and perhaps a biscuit).
33
+
34
+ ## Getting Started
35
+
36
+ 1. While not essential, we recommend running the [device setup process](https://setup.particle.io/) on your Particle device first. This ensures your device's firmware is up-to-date and you have a solid baseline to start from.
37
+
38
+ 2. If you haven't already, open this project in Visual Studio Code (File -> Open Folder). Then [compile and flash](https://docs.particle.io/getting-started/developer-tools/workbench/#cloud-build-and-flash) your device. Ensure your device's USB port is connected to your computer.
39
+
40
+ 3. Verify the device's operation by monitoring its logging output:
41
+ - In Visual Studio Code with the Particle Plugin, open the [command palette](https://docs.particle.io/getting-started/developer-tools/workbench/#particle-commands) and choose "Particle: Serial Monitor".
42
+ - Or, using the Particle CLI, execute:
43
+ ```
44
+ particle serial monitor --follow
45
+ ```
46
+
47
+ 4. Uncomment the code at the bottom of the cpp file in your src directory to publish to the Particle Cloud! Login to console.particle.io to view your devices events in real time.
48
+
49
+ 5. Customize this project! For firmware details, see [Particle firmware](https://docs.particle.io/reference/device-os/api/introduction/getting-started/). For information on the project's directory structure, visit [this link](https://docs.particle.io/firmware/best-practices/firmware-template/#project-overview).
50
+
51
+ ## Particle Firmware At A Glance
52
+
53
+ ### Logging
54
+
55
+ The firmware includes a [logging library](https://docs.particle.io/reference/device-os/api/logging/logger-class/). You can display messages at different levels and filter them:
56
+
57
+ ```
58
+ Log.trace("This is trace message");
59
+ Log.info("This is info message");
60
+ Log.warn("This is warn message");
61
+ Log.error("This is error message");
62
+ ```
63
+
64
+ ### Setup and Loop
65
+
66
+ Particle projects originate from the Wiring/Processing framework, which is based on C++. Typically, one-time setup functions are placed in `setup()`, and the main application runs from the `loop()` function.
67
+
68
+ For advanced scenarios, explore our [threading support](https://docs.particle.io/firmware/software-design/threading-explainer/).
69
+
70
+ ### Delays and Timing
71
+
72
+ By default, the setup() and loop() functions are blocking whilst they run, meaning that if you put in a delay, your entire application will wait for that delay to finish before anything else can run.
73
+
74
+ For techniques that allow you to run multiple tasks in parallel without creating threads, checkout the code example [here](https://docs.particle.io/firmware/best-practices/firmware-template/).
75
+
76
+ (Note: Although using `delay()` isn't recommended for best practices, it's acceptable for testing.)
77
+
78
+ ### Testing and Debugging
79
+
80
+ For firmware testing and debugging guidance, check [this documentation](https://docs.particle.io/troubleshooting/guides/build-tools-troubleshooting/debugging-firmware-builds/).
81
+
82
+ ### GitHub Actions (CI/CD)
83
+
84
+ This project provides a YAML file for GitHub, automating firmware compilation whenever changes are pushed. More details on [Particle GitHub Actions](https://docs.particle.io/firmware/best-practices/github-actions/) are available.
85
+
86
+ ### OTA
87
+
88
+ To learn how to utilize Particle's OTA service for device updates, consult [this documentation](https://docs.particle.io/getting-started/cloud/ota-updates/).
89
+
90
+ Test OTA with the 'Particle: Cloud Flash' command in Visual Studio Code or the CLI command 'particle flash'!
91
+
92
+ This firmware supports binary assets in OTA packages, allowing the inclusion of audio, images, configurations, and external microcontroller firmware. More details are [here](https://docs.particle.io/reference/device-os/api/asset-ota/asset-ota/).
93
+
94
+ ## Support and Feedback
95
+
96
+ For support or feedback on this template or any Particle products, please join our [community](https://community.particle.io)!
97
+
98
+ ## Version
99
+
100
+ Template version 1.0.2
@@ -0,0 +1,2 @@
1
+ name=myProject
2
+ #assetOtaDir=assets
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Project myProject
3
+ * Author: Your Name
4
+ * Date:
5
+ * For comprehensive documentation and examples, please visit:
6
+ * https://docs.particle.io/firmware/best-practices/firmware-template/
7
+ */
8
+
9
+ // Include Particle Device OS APIs
10
+ #include "Particle.h"
11
+
12
+ // Let Device OS manage the connection to the Particle Cloud
13
+ SYSTEM_MODE(AUTOMATIC);
14
+
15
+ // Run the application and system concurrently in separate threads
16
+ SYSTEM_THREAD(ENABLED);
17
+
18
+ // Show system, cloud connectivity, and application logs over USB
19
+ // View logs with CLI using 'particle serial monitor --follow'
20
+ SerialLogHandler logHandler(LOG_LEVEL_INFO);
21
+
22
+ // setup() runs once, when the device is first turned on
23
+ void setup() {
24
+ // Put initialization like pinMode and begin functions here
25
+ }
26
+
27
+ // loop() runs over and over again, as quickly as it can execute.
28
+ void loop() {
29
+ // The core of your code will likely live here.
30
+
31
+ // Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
32
+ // Logging.info("Sending Hello World to the cloud!");
33
+ // Particle.publish("Hello world!");
34
+ // delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!
35
+ }
@@ -1,18 +0,0 @@
1
- /*
2
- * Project <%=name%>
3
- * Description:
4
- * Author:
5
- * Date:
6
- */
7
-
8
- // setup() runs once, when the device is first turned on.
9
- void setup() {
10
- // Put initialization like pinMode and begin functions here.
11
-
12
- }
13
-
14
- // loop() runs over and over again, as quickly as it can execute.
15
- void loop() {
16
- // The core of your code will likely live here.
17
-
18
- }