Cloud Agent crashes: "invalid character 'y' after top-level value"

Hi! I am having a similar issue, running macOS Sonoma 14.6 on an Intel MacBook. I downloaded and installed successfully the agent, but somehow I could not communicate with my Arduino. The icon in the menu bar was grey, so I tried to delete the agent and download it again. What happens now every time I open it is that the icon shows up momentarily in the menu bar, but disappears immediately, as if it had crashed. I get no report, so I am unsure what's going on. Thank you for your attention!

Hi @marcvillanuevamir. I'm going to ask you to run Arduino Create Agent from the command line, then post the output in a reply here.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. If Arduino Create Agent is running, terminate it by clicking the Arduino icon in the macOS "menu bar" at the top of your screen and then selecting "Quit Agent" from the menu.
  2. Open macOS Launchpad.
  3. Type terminal in the "Search" field.
  4. Click on the "Terminal" icon.
    A "Terminal" window will open.
  5. Type the following command in the Terminal window:
    "/Applications/ArduinoCreateAgent.app/Contents/MacOS/Arduino_Create_Agent"
    
  6. Press the Enter key.
  7. Repeat the operation in Arduino Cloud, just as you did before when you encountered the problem.
  8. Switch back to the Terminal window.
  9. Press the Command+A keyboard shortcut.
    This will select all the text in the Terminal window.
  10. Press the Command+C keyboard shortcut.
    This will copy the selected text to the clipboard.
  11. Open a forum reply here by clicking the "Reply" button.
  12. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the output is correctly formatted.
    Code block icon on toolbar
  13. Press the Command+V keyboard shortcut.
    This will paste the output into the code block.
  14. Move the cursor outside of the code block markup before you add any additional text to your reply.
  15. Click the "Reply" button to post the output.

Please let me know if you have any questions or problems while following those instructions.

Last login: Sat Aug  3 10:29:13 on ttys000
marc@marcvillanuevamir ~ % /Applications/ArduinoCloudAgent.app/Contents/MacOS/Arduino_Cloud_Agent ; exit;
INFO[0000] using config from default: /Users/marc/Library/Application Support/ArduinoCreateAgent/config.ini 
INFO[0000] additional config file not found in config.ini 
INFO[0000] Version:1.6.0                                
INFO[0000] Hostname: marcvillanuevamir.local            
INFO[0000] Garbage collection is on using Standard mode, meaning we just let Golang determine when to garbage collect. 
INFO[0000] You specified a serial port regular expression filter: usb|acm|com 
INFO[0000] the autostart file /Users/marc/Library/LaunchAgents/ArduinoCreateAgent.plist already exists: nothing to do 
INFO[0000] Checking if the Arduino certificate is in the keychain 
INFO[0000] Retrieving certificate's expiration date     
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /                         --> main.homeHandler (2 handlers)
[GIN-debug] POST   /upload                   --> main.uploadHandler (2 handlers)
[GIN-debug] GET    /socket.io/               --> main.(*WsServer).ServeHTTP-fm (2 handlers)
[GIN-debug] POST   /socket.io/               --> main.(*WsServer).ServeHTTP-fm (2 handlers)
[GIN-debug] WS     /socket.io/               --> main.(*WsServer).ServeHTTP-fm (2 handlers)
[GIN-debug] WSS    /socket.io/               --> main.(*WsServer).ServeHTTP-fm (2 handlers)
[GIN-debug] GET    /info                     --> main.infoHandler (2 handlers)
[GIN-debug] POST   /pause                    --> main.pauseHandler (2 handlers)
[GIN-debug] POST   /update                   --> main.updateHandler (2 handlers)
[GIN-debug] GET    /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] POST   /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] PUT    /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] PATCH  /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] HEAD   /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] OPTIONS /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] DELETE /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] CONNECT /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] TRACE  /v2/*path                 --> main.loop.WrapH.func4 (2 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on 127.0.0.1:8991
[GIN-debug] Listening and serving HTTPS on 127.0.0.1:8991
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] [ERROR] listen tcp 127.0.0.1:8991: bind: address already in use
INFO[0000] Error trying to bind to port: listen tcp 127.0.0.1:8991: bind: address already in use, so exiting... 
[GIN-debug] Listening and serving HTTPS on 127.0.0.1:8992
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
ERRO[0000] Error downloading serial-discovery: invalid character 'y' after top-level value 
panic: invalid character 'y' after top-level value

goroutine 25 [running]:
main.(*SerialPortList).runSerialDiscovery(0x0?)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/serial.go:130 +0x628
main.(*SerialPortList).Run(0x0?)
	/Users/runner/work/arduino-create-agent/arduino-create-agent/serial.go:118 +0x25
created by main.loop in goroutine 14
	/Users/runner/work/arduino-create-agent/arduino-create-agent/main.go:410 +0x14ee

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]


Thank you for your instructions! This was its outcome. For some reason I could not run the application from the terminal, so I opened the package manually and ran it from there. I don't think that matters anyway.

Great work on finding a way to obtain the logs even though you encountered difficulties!

That was my fault. I see now that the Arduino Create Agent developers recently renamed the executable from Arduino_Create_Agent to Arduino_Cloud_Agent. I'll make sure to make note of this so that I will provide the correct instructions in the future when providing support to Arduino Create/Cloud Agent users. I apologize for any confusion my mistake caused.

The problem is now clear:

The Arduino Create Agent developers are tracking the bug here:

I apologize for any inconvenience this has caused. Work on a fix is already in progress.

I'll provide instructions you can follow to force Arduino Create Agent to regenerate this file that was corrupted due to the bug. Hopefully this time the file will be created correctly:

  1. Start macOS "Finder".
  2. Navigate to the following folder:
    /Users/<username>
    
    (where <username> is your macOS username)
  3. You should see a folder named .arduino-create. If not, press the Command+Shift+. keyboard shortcut to reveal this hidden folder.
  4. Control-click the sketch folder.
    A context menu will open.
  5. Select "Move to Trash" from the menu.

Now try using Arduino Cloud again, just as you did before. Hopefully this time everything will work as expected.


Please let me know if you have any questions or problems while following those instructions.

Ok! I followed your steps and it worked! At least now the icon stays in the menu bar without crashing :slight_smile:
In Safari, though, when I try to add a new device from Arduino Cloud, I get this message, as the agent weren't recognised:


In Firefox, the board is recognised but the process fails during the firmware checking. Last time I could do this in Safari and even renamed the device, but it would fail on the next step. Somehow it feels very unstable.
I uploaded and ran sketches on the board without complications, so I don't think there is any issue with the board itself or with the cable... Maybe this is already beyond your scope. In any case, thank you for helping me get the agent working!

OK, this is definitely progress even if we aren't quite there yet!

This problem could be caused by certain security restrictions of the web browser blocking the communication between Arduino Cloud and Arduino Cloud Agent.

I'll provide instructions you can follow to configure Arduino Cloud Agent so that the communication will not be blocked:

  1. Start Arduino Cloud Agent if it is not already running.
    If you see an Arduino Cloud Agent icon on the macOS "menu bar" then it is running.
  2. Click on the Arduino Cloud Agent icon on the macOS menu bar.
    A menu will open.
  3. Select "Manage HTTPS Certificate" from the menu.1
    The "Arduino Agent: Manage HTTPS certificate" dialog will open.
  4. If there is an "Install the certificate for Safari" button in the dialog, click that button.
    A "You are making changes to your Certificate Trust Settings" dialog will open.
  5. Enter your macOS user password in the "You are making changes to your Certificate Trust Settings" dialog.
  6. Click the "Update Settings" button.
    The "The HTTPS certificate has been installed correctly" dialog will appear.
  7. Click the "OK" button in the dialog.

After doing that, try using Arduino Cloud again. This time Arduino Cloud should be able to recognize that Arduino Cloud Agent is running and everything should work as expected.


Please let me know if you have any questions or problems while following those instructions.



1. "If your board is not detected by Arduino Cloud Editor". Arduino Help Center.

The certificate was already installed. I uninstalled and installed it again, but I keep encountering the same issue:

I retried it now and could name the device, but the next window blocked me again. I hope this log helps you identify the issue:

OK, this is more progress, even if it might not seem like it.

This error indicates that some process has the serial port of your Arduino board open. Do you have Arduino IDE running on your computer? This error can occur if the Arduino IDE Serial Monitor is open (which is not always obvious since the Arduino IDE 2.x Serial Monitor is a tab in the bottom panel of the IDE window). If so, close Arduino IDE and then try again.

Alright.. I can't see what might be keeping that serial port busy, since I had neither the Arduino IDE nor anything else open. Just to troubleshoot, I shut down the computer completely, and on reboot the same issue from the beginning appeared (the agent crashing every time I ran it).
So I deleted that hidden folder again to get it back, and now it's up in the menu bar again, but once more the process won't progress. Every time it's different: suddenly it gets stuck during firmware check, and then (after both restarting the agent and resetting the Arduino) uploads the sketch but gets stuck while establishing secure connection. Last time I tried, I got that busy serial message again. And again, no application is open. I've even uploaded the Blink example so the Arduino itself was not running any serial by itself. I don't know what else to do, I am sorry that my troubleshooting is turning up to be so unpredictable.

OK, this is valuable information. It tell us that Arduino Cloud is able to open the serial port of the board sometimes rather than it being a situation where it is persistently blocked by some external process.

Which Arduino board are you using?

Maybe it is a leftover process spawned by Arduino Cloud during a previous upload attempt that is blocking the serial access during subsequent upload attempts.

Hey! Thank you for your time and your encouraging messages!
I am using an (official) Arduino Uno R4 WiFi.

I'm not sure exactly which point in the process this occurs. I just ran through the Device creation process a couple of times successfully with my UNO R4 WiFi board, but didn't notice that step. Is it during the Device creation workflow, or is it after you already created a Thing and are running the Thing sketch on the board?

If it is during the Device creation workflow, please provide the rest of the text of the dialog that is shown when it gets stuck. You can post a screenshot of the dialog when it is in that state.

Ok! Here comes a full walkthrough:

  1. I run the agent

  2. I plug the Arduino board

  3. I open Arduino Cloud and create a Thing

  4. I click on "Associate device"

  5. I click on "Set up new device" and select an Arduino device

  6. I am prompted "We could not find any Arduino device"

  7. I quit the agent, restart the Arduino with its button and boot the agent again

  8. I click on "Try again"

  9. Now I am prompted "Arduino UNO R4 WiFi found". I click on "Configure"

  10. I am prompted "Checking your device connectivity". It takes a long time on the step 1: "Checking firmware"

  11. I am prompted "We were not able to update the firmware"

  12. I quit the agent, unplug the board, replug it in another port, then run the agent again and click "Try again"

  13. Again as in 10 and 11. The only dialog I am shown is "Something went wrong!"

  14. I decide to give up on the Thing approach and go straight to "Add new device" from the Arduino Cloud webpage. This time everything runs soomthly, firmware check takes one second, I am asked to give a name to the device (I love the ones that are suggested, by the way!), and when I go on forward, I get this error message again:

  1. I quit the agent and run it again, I restart the board with one press, then with two presses, all these steps return the same message.
  2. I unplug and replug the board to a different port, and now it looks like it moves forward to "Make your device IoT-ready", up to step 1 "Uploading sketch", step 2 (extremely fast, I can't even see what is that) and step 3 ("Configuring Secure Element"). Step 3 takes a long time
  3. I get the following error message:

  1. I click on "Try again", same result.

I wrote this thoroughly so you could see how I manage to move forward only with many reboots, resets, replugs and rituals. And in the end, something blocks me. Maybe is there something wrong with my board or my cable after all?

And yet there has been some progress. Now one the attempts of creating a device successfully appears in the devices list as Loree. But as you can see here, I have the board plugged to the computer and it still appears as offline:

I restarted the agent, the board, etc. to no avail. I don't know if the configuration was truly unsuccessful and all we are dealing here with are leftovers, or whether there is a way to force the connection to refresh and see it as online.

Nice! Persistence pays off I guess :slight_smile:

The Device status will only change to "Online" once you have created an Arduino Cloud IoT Thing and uploaded the Thing sketch to the board.

The Thing sketch contains the code that connects the board to your Wi-Fi access point, through the Internet, and to the Arduino Cloud servers. It is that connection to the Arduino Cloud server that causes the Device to be considered to have an "Online" status by Arduino Cloud. A connection between the board and your computer through the USB cable alone does not cause an "Online" Arduino Cloud Device status.

I have an update to share on this specific problem: The bug has been fixed and the fix is now released in version 1.6.1 of Arduino Cloud Agent. Arduino Cloud Agent will automatically self-update to the new version the next time you use Arduino Cloud while Arduino Cloud Agent is running.

So Arduino Cloud users will no longer be affected by this problem of the corrupted data file causing Cloud Agent to crash once the update has completed.

For anyone who is not able to accomplish the update due to 1.6.0 crashing from the corrupted file, you can manually install 1.6.1 (which will update 1.6.0). The installer can be downloaded from the links listed under the Assets section of the release page:

https://github.com/arduino/arduino-create-agent/releases/latest