简体   繁体   中英

Arduino Create Agent JS CLIENT how to use

Welcome, currently, I want to upload code to Arduino using JavaScript (NodeJS), I HATE using FIRMATA to upload code, I want to use the official Arduino create agent and Arduino create agent js client

https://github.com/arduino/arduino-create-agent-js-client

I just downloaded the arduino create agent, I run the below in empty directory

git clone https://github.com/arduino/arduino-create-agent-js-client.git

I inserted arduino nano(old bootloader) in COM7, thus I changed(edited) the file .\demo\app.jsx line 189-205 to,

handleUpload() {
    const target = {
      board: 'arduino:avr:nano',
      port: 'COM7',
      network: false
    };

    this.setState({ uploadingPort: target.port });
    daemon.boardPortAfterUpload.subscribe(portStatus => {
      if (portStatus.hasChanged) {
        this.setState({ uploadingPort: portStatus.newPort });
      }
    });

    // Upload a compiled sketch.
    daemon.uploadSerial(target, 'serial_mirror', { bin: HEX });
  }

then I run

npm run dev

since the local host runs on http://localhost:8000/ I edited the config file

C:\Users\USER\AppData\Roaming\ArduinoCreateAgent\config.ini

and set origins = http://localhost:8000

that is

gc = std  # Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)
hostname = unknown-hostname  # Override the hostname we get from the OS
regex = usb|acm|com  # Regular expression to filter serial port list
v = true  # show debug logging
appName = CreateAgent/Stable
updateUrl = https://downloads.arduino.cc/
origins = http://localhost:8000 #this is where I have setted
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests
crashreport = false # enable crashreport logging

问题

it keep on uploading as shown above

please help

There are a few steps to get this working:

  • Install the Arduino Create Agent
  • Modify the config.ini file to set origins = http://localhost:8000
  • Update the target board and port in demo\app.jsx
  • Replace the sketch to download to the board in demo\serial_mirror.js
  • Allow the demo app to reach builder.arduino.cc by disabling CORS in your browser

You have done the first three but not the last two.

Replacing the sketch

The demo app hard codes the sketch to download in serial_mirror.js

This can be replaced with the desired sketch by exporting the compiled binary from the Arduino app. See screenshot below. The exported binary is saved to the sketch folder (the sketch needs to be writable).

导出已编译的二进制文件

The exported binary needs to be base 64 encoded. You can convert the binary with the following command in WSL:

base64 -w 0 exported.sketch.bin > exported.sketch.b64

The string in demo\serial_mirror.js needs to be replaced with the new sketch's base 64 string. ie

export const HEX = '<string from exported.sketch.b64>';

Disabling CORS in your browser

The developer console in the browser displays CORS errors when trying to upload the sketch.

上传时出现 CORS 错误

You can temporarily disable this security check by starting a separate instance of your browser. eg start Chrome with the --disable-web-security flag:

"c:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=c:\\windows\\temp

The demo app can then upload the sketch without any CORS errors.

See this other SO answer for an overview for why this fails.

The request to builder.arduino.cc that fails is required by the app to determine the command line and tool signature to use when programming the board.

上传成功

Gotchas

You will need to close any other apps using the COM port and force your Arduino into programming mode (if necessary, by pressing the programming button on the board).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM