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.index.bs: Your entry point file.
Step 2: Write Code
Open 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?
- Scan: The CLI scans for nearby BlueScript devices over Bluetooth.
- Compile: The CLI compiles your project into Native Code on your PC.
- Upload: Upon selecting your device, it transfers the binary 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 test a command quickly without editing a file? Try the interactive mode!
Run bscript repl in your terminal. You can type commands like console.log("Hello") and see the results instantly on the device.