Create project and Run
Now that your environment is set up and the runtime is flashed to your device, let's write and run your first BlueScript program.
Step 1: Create a Project
Create a new directory for your project. The CLI will generate the necessary configuration files.
bscript project create hello-bluescript
cd hello-bluescript
This creates a simple project structure:
bsconfig.json: Project configuration (see bsconfig.json for details).src/: Source directory (srcDirinbsconfig.json).src/index.bs: Entry file (entryFileinbsconfig.json).
Step 2: Write Code
Open src/index.bs in your code editor and write a simple program.
console.log("Hello world!");
Step 3: Run Wirelessly
Make sure your ESP32 is powered on. Since the runtime is already flashed, you can disconnect the USB cable and power the device via a battery or USB power bank.
Run the following command in your terminal:
bscript project run
What happens next?
- Connect: The CLI scans for a BlueScript device over Bluetooth whose name matches
deviceNameinbsconfig.json(default:"BLUESCRIPT") and connects automatically. - Compile: The CLI compiles your project into Native Code on your PC.
- Upload: The compiled binary is transferred to the device via Bluetooth.
- Execute: The ESP32 executes the code immediately.
Please note that programs uploaded via bscript project run are not persisted after a reboot.
If you restart or power off the device, the program will be lost. You will need to execute bscript project run again to re-upload your code.
Future Roadmap:
We are planning to introduce a bscript project deploy command. This command will permanently install your application, allowing it to start automatically when the device powers on.
Want to experiment without editing files on every try? After you have a project, run bscript project run --with-notebook for a browser-based Notebook, or see REPL & Notebook for all interactive modes.
To run BlueScript on the host runtime without an ESP32, see Try Without Microcontroller.