Share My Creation Create projects with unique serial number.

janderkan

Active Member
Licensed User
I had the same wish as this user, and this is my solution.
I wanted to have a unique serialnumber in every piece of hardware.
Using Lora communication the Mac was too long.
The solution is a B4J project but it solves a B4R problem.
It will create different bin files to upload to my hardware and it can also upload them.

First add a code module named Serialnumber to your B4R project.
B4X:
private Sub Process_Globals
    Public SN As ULong = 44
End Sub
Compile your project.
This will create a b4r_serialnumber.cpp file in project/objects/src folder.

Create a batch file in your project folder called compile.bat
B4X:
@Echo off

C:\PROGRA~2\Arduino\arduino-builder -compile -logger=machine -hardware (VERY LONG LINE)

EXIT /B %ERRORLEVEL%
Your find the very long line in the log when you compile your project
One of the first lines, look for \arduino-builder -compile
Now you can manually change the CPP file and run the batch file to compile.

Next create a batch file in your project folder called burn.bat
B4X:
@Echo off

C:\path to esptool\esptool.exe -vvvv -cd nodemcu -cb 256000 -cp COM7 -ca 0x00000 -cf C:\path to project\Project\Objects\bin\src.ino.bin

EXIT /B %ERRORLEVEL%
Now you can manually burn the file to your hardware.

To automate your process, change the burn.bat and replace src.ino.bin with %1
B4X:
@Echo off

C:\path to esptool\esptool.exe -vvvv -cd nodemcu -cb 256000 -cp COM7 -ca 0x00000 -cf C:\path to project\Project\Objects\bin\%1

EXIT /B %ERRORLEVEL%
Finally use the attached B4J project.
Select Compile.
Select the B4R project.
Select starting serial number
Select how many files you want.
This will create the files in project/objects/bin folder

Select Burn.
Select the B4R project.
Select starting serial number
Select how many files you want to burn.
This will help you burn all the files to your hardware.

 

Attachments

Top