Asked

Help With EZ-Script Coding

I'm working on a project with my EZ-B v4, and I need some assistance with coding the GetDigital command. My aim is to use pin D22 as an input pin to receive a high/low digital signal from an R/C receiver. The receiver uses a PWM-to-digital output device on one of its channels. This setup will allow me to switch my robot's drive wheels between ARC (automatic mode) and R/C control (manual mode).

The script below is intended to monitor the state of pin D22 and provide verbal feedback. When in Automatic Mode, ARC will control the wheels and all sensors. In manual Mode, a standard radio control transmitter will handle the wheel operations. I need this functionality implemented in both EZ-Script and JavaScript.

Here's my current EZ-Script code:

$X = GetDigital(D22)
if ($X = 0)
  $X = "PASS"
  EzbSay("in  manual Mode")
elseif ($X = 1)
  $X = "FAIL"
  EzbSay("in Automatic Mode")
endif

Could you review it and help me ensure that it performs correctly? Additionally, guidance on translating this into JavaScript for the ARC environment would be greatly appreciated. Thank you!


Related Hardware EZ-B v4
Related Controls Script EZ-Script Console

ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

#57  

ok, great, I will try this version, very promising .

I like the LED states you created for me, I plan on keeping them.

Just for an extra, I would like to see this small test script that I can toggle $AllowAutoReconnect manually as you mentioned.

Author Avatar
PRO
Canada
#58  

Great - glad you liked the LED states. Below are two tiny JavaScript Script-skill snippets you can paste into ARC’s Script skill (JavaScript tab). One toggles $AllowAutoReconnect and announces the new state. The other just prints/shows the current state (useful to check without toggling).

Instructions (quick)

  • Project -> Add robot skill -> Scripting -> Script
  • Name the skill (example: Toggle AutoReconnect)
  • Open the JavaScript tab, paste the code below, Save.
  • Click Start to run the script once; it will toggle the variable and exit (or print status).
  • If you want a clickable UI, add a Button control that runs the script skill (or keep the Script skill and Start it manually).

Toggle script (one-shot)

  • Paste this into a Script skill JavaScript tab named e.g. "Toggle AutoReconnect" and Run/Start it to toggle once.
/*
Toggle AutoReconnect (JavaScript)
Toggles the global variable $AllowAutoReconnect between "1" and "0",
prints and announces the new value.
*/
var ezbIndex = 0; // change if you use different ezb index

// Read current value (default "1" if not defined)
var current = getVar("$AllowAutoReconnect", "1");
var newVal = (current === "1") ? "0" : "1";

// Save new value
setVar("$AllowAutoReconnect", newVal);

// Console feedback
print("AutoReconnect: " + current + " -> " + newVal);

// Announce (prefer EZB TTS if connected, fallback to PC TTS)
try {
  if (EZB.isConnected(ezbIndex)) {
    Audio.sayEZB("Auto reconnect " + (newVal === "1" ? "enabled" : "disabled"), ezbIndex);
  } else {
    Audio.say("Auto reconnect " + (newVal === "1" ? "enabled" : "disabled"));
  }
} catch (e) {
  print("TTS failed: " + e);
}

Status script (non-destructive)

  • Paste into a Script skill JavaScript tab named e.g. "Show AutoReconnect Status" and Start it to display the current state.
/*
Show AutoReconnect Status (JavaScript)
Prints and announces current $AllowAutoReconnect value without changing it.
*/
var ezbIndex = 0; // adjust if needed

var current = getVar("$AllowAutoReconnect", "1");
print("Current $AllowAutoReconnect = " + current);

try {
  if (EZB.isConnected(ezbIndex)) {
    Audio.sayEZB("Auto reconnect is " + (current === "1" ? "enabled" : "disabled"), ezbIndex);
  } else {
    Audio.say("Auto reconnect is " + (current === "1" ? "enabled" : "disabled"));
  }
} catch (e) {
  print("TTS failed: " + e);
}

Extra tips

  • To temporarily disable auto reconnect from any other script, you can run the Toggle script above, or set the variable directly in JavaScript with: setVar("$AllowAutoReconnect", "0") // disable setVar("$AllowAutoReconnect", "1") // enable
  • If you’d like, I can give step-by-step instructions to add a GUI button in ARC that runs the Toggle script with a single tap.
  • I’ll avoid creating EZ-Script code (I can help translate EZ-Script into JavaScript or Python if you show it), so these JavaScript scripts are the recommended approach.

Want the button instructions or a single script that toggles and then updates an on-screen indicator (or file log) automatically?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#59  

Ok, so I fixed the code in the connection skill and removed that extra EZB connect skill. Added your new combined EZB reconnect + D22 monitor JS.

It does run alot better. The LED blink is back, im happy.  Only had a couple disconnects.

First disconnect only happened shortly after I switched from manual to automatic mode. So I reconnected, and I think ARC got confused because it announced it was in manual mode but was really still in automatic mode. Here is the error message inside the EZB_D22 script:

6:41:14 PM - Mode change -> AUTOMATIC detected (D22=1). Running HB25 Init and resuming automatic control. Wednesday, December 24, 2025 6:41:20 PM - Mode change -> manual detected (D22=0). Releasing servos and stopping automatic movement. Wednesday, December 24, 2025 6:41:21 PM - EZB index 0 not connected. Attempting to connect. Done (00:00:36.0940815)

It did settle down right after.

My second disconnect happened while I am writing this (while in Automatic mode)

Meanwhile I will also try the two toggle autoreconnect scripts just created.

#60  

One thing I forgot to add, sometimes when it reconnects itself, I noticed that I have to click on Start button of the EZB_D22 script for it wo announce what state it was it last.

#61  

Just tried both of the Toggle Auto Connect scripts, neither on work, due to some syntax error: Error: Missing 1 closing statement (ENDIF/ENDREPEAT/ENDREPEATUNTIL/ENDREPEATWHILE/etc) Done (00:00:00)

Author Avatar
PRO
Canada
#62  

Thanks - that error message explains what happened. The "Missing 1 closing statement" is the EZScript parser complaining because JavaScript was put into an EZScript editor (or run via the EZScript Console). Your toggle snippets are JavaScript - they must be placed in the Script skill JavaScript tab (not the EZScript tab or EZScript Console).

Below I’ll give:

  • Correct JavaScript versions of the Toggle and Status scripts (paste into a Script skill JavaScript tab).
  • A oneshot "Announce Mode Now" JavaScript snippet so you can force an announce without restarting anything.
  • Quick instructions for installing and running them, and troubleshooting tips for the disconnect / announce issues you reported.
  1. Toggle AutoReconnect (JavaScript)
  • Add a Script skill (Project Add robot skill Scripting Script).
  • Open the JavaScript tab, paste this code, Save.
  • Start the script (it runs once and exits). You can also run it from a UI button or with controlCommand().
// Toggle AutoReconnect (JavaScript)
// Toggles $AllowAutoReconnect between "1" and "0", prints and announces the new value.
// Put this in a Script skill JavaScript tab and Start it to toggle once.

var ezbIndex = 0; // change if you use a different EZB index

// read current (default "1")
var current = getVar("$AllowAutoReconnect", "1");
var newVal = (current === "1") ? "0" : "1";
setVar("$AllowAutoReconnect", newVal);

// feedback
print("AutoReconnect: " + current + " -> " + newVal);

// TTS: prefer EZB if connected, fallback to PC
try {
  if (EZB.isConnected(ezbIndex)) {
    Audio.sayEZB("Auto reconnect " + (newVal === "1" ? "enabled" : "disabled"), ezbIndex);
  } else {
    Audio.say("Auto reconnect " + (newVal === "1" ? "enabled" : "disabled"));
  }
} catch (e) {
  print("TTS failed: " + e);
}
  1. Show AutoReconnect Status (JavaScript)
  • Use this when you want to check status without toggling.
// Show AutoReconnect Status (JavaScript)
// Put in a Script skill JavaScript tab and Start it to read status.

var ezbIndex = 0;
var current = getVar("$AllowAutoReconnect", "1");
print("Current $AllowAutoReconnect = " + current);

try {
  if (EZB.isConnected(ezbIndex)) {
    Audio.sayEZB("Auto reconnect is " + (current === "1" ? "enabled" : "disabled"), ezbIndex);
  } else {
    Audio.say("Auto reconnect is " + (current === "1" ? "enabled" : "disabled"));
  }
} catch (e) {
  print("TTS failed: " + e);
}
  1. Announce Mode Now (JavaScript)
  • This reads the $Mode global variable and announces it. Useful when the monitor did not announce after a reconnect.
// Announce Mode Now (JavaScript)
// Reads $Mode and announces it. Put in JavaScript tab and Start it.

var ezbIndex = 0;
var mode = getVar("$Mode", "Unknown");
print("Current $Mode = " + mode);

try {
  if (EZB.isConnected(ezbIndex)) {
    Audio.sayEZB("Current mode is " + mode, ezbIndex);
  } else {
    Audio.say("Current mode is " + mode);
  }
} catch (e) {
  print("TTS failed: " + e);
}

Why you saw the syntax error

  • The error you saw comes from EZScript, not JavaScript. If you run JavaScript in an EZScript editor or the EZScript Console it tries to interpret it as EZScript (needs ENDIF etc.). Always paste JavaScript into the Script skill JavaScript tab.

Why the monitor sometimes needs Start clicked after reconnect

  • Likely causes:
    • There are still two scripts trying to manage reconnect/start. Make sure you removed the old EZB Reconnect Monitor from Connection Established scripts so only the merged monitor is autostarted.
    • Or the merged monitor stops (rare) when it loses EZB and some other skill is stopping it. The merged JS I gave is designed to run on the PC side and should keep running and do its own reconnect attempts. Verify the merged monitor Script skill is running and autostarted.
  • Quick check:
    • In Connection Settings Connection Established Scripts remove any line that starts the old reconnect skill.
    • Keep only the one that autostarts your merged monitor. Example: controlCommand("Merged EZB Monitor","ScriptStart") controlCommand("HB25 Init","ScriptStartWait") sleep(500)

If you want the merged monitor to always start (and re-start) when you connect:

  • Add this single-line to Connection Settings Connection Established Scripts (adjust exact name): controlCommand("Merged EZB Monitor","ScriptStart")

Important checks / remedies to reduce disconnects when switching modes

  • Hardware:
    • Confirm a common ground between EZB, receiver/Pololu/selector, and HB25 battery/power.
    • Watch for power dips when you flip the selector - high current or a servo twitch can drop WiFi and cause the EZB to disconnect.
    • If using batteries, verify voltage does not dip below the EZB low battery warning threshold during the switch.
  • Software:
    • Increase debounce in the monitor if switching causes quick transients. Try debounceMs = 300 in the monitor.
    • Ensure $AllowAutoReconnect = "1" for normal operation; set to "0" temporarily if you want to disconnect and stay disconnected.

Next steps I suggest

  1. Confirm you placed the Toggle script in the JavaScript tab and run again.
  2. Confirm the Connection Established script only starts your merged monitor (remove the old reconnect monitor).
  3. If the monitor still doesn’t announce its last mode after reconnect, run the "Announce Mode Now" script to see the stored $Mode and hear the announce. If $Mode is wrong, the monitor’s read path may be getting stale - increase debounce and add a short sleep before announcing after reconnect (I can patch the merged monitor to do that).
  4. If you still see disconnects at a specific switch event, try these tests:
    • Temporarily disconnect the HB25/servos (no load) and flip the selector - if no disconnects occur, it is power/servo related.
    • Monitor the log file for the reconnect timestamps and share that log snippet if you want me to analyze timing.

If you want, I can:

  • Provide a tiny revision of your merged monitor to add a short "settle" sleep and re-read the D22 several times after reconnect before announcing (that will reduce false announces).
  • Provide the exact one-line ControlCommand entries you should keep/remove in Connection Settings so you don’t accidentally restart an old reconnect skill.

Which would you like next?

  • I recommend: (a) try the Toggle script in the JavaScript tab, (b) confirm the Connection Established scripts only start your merged monitor, (c) if you still want me to tweak the merged monitor to add the extra settle-read and guarantee announce after reconnect, say "Please add settle read" and I’ll paste the small revision.

I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#63  

Im beginning to think alot of my issues are network connection related. I recently added the PandoraBot skill to this project to see. This laptop/tablet does not have a LAN port, its strictly wifi. So as I have described before, I use the built in wifi to connect to EZB (seems to work best) and a wifi dongle to connect to the internet ( I can use built in wifi to get to internet when not dongle is not in use). Many times, while having ARC running, if I try to call up a web page (ie:synthiam) it takes forever to load or never load unless I disonnect ARC or ARC disconnects itself. I also would note, when I think things are stable, when trying to use Pandorabot as a test, many times it may reply, only to lose it connection next time, then maybe work again if the ARC program works again (from be reconnecting if it had disconnected). I have also done a test with using one of the more simple JS we created. I could leave the ARC program running and connected to the EZB idle, no disconnects and I could toggle the D22 line and still no disconnects (usually the disconnects can start quickly). I am thinking that this laptop may not like the two wifis working together, which I absolutely need for this project.  So yeah, I need to come up with another plan. It may be to use ARC to run robot but not AI skills, and/or use ARC for AI skills but no without any robot actions. Any thoughts?

Author Avatar
PRO
Canada
#64  

Good troubleshooting - your description matches a common dualWiFi problem: when your PC connects to the EZ-B AP and your internet dongle at the same time, Windows can switch routes and default gateway in a way that breaks internet access or causes frequent network reconfiguration. ARC, PandoraBot (and any Internet skill) rely on a stable internet route; frequent adapter switching or a bad default route will cause the intermittent replies and disconnects you’re seeing.

Below are practical options (ranked by how well they solve the root problem), concrete steps you can try on Windows, and simple alternatives if changing networks isn’t possible. Tell me which OS version you have (Windows 10 / 11), what adapter names show in Network Connections, and whether the EZB is currently in AP mode (192.168.1.1) or client mode - I’ll tailor exact commands for you.

Recommended solutions (best fallback)

  1. Best: Put the EZB in Client Mode (recommended)
  • Have the EZB join your normal WiFi network (the one that gives internet via the dongle/router). That means your PC and EZB are on the same LAN and you only use one network interface on the PC. No route conflicts, no disconnects.
  • How: connect to the EZB AP (192.168.1.1) and open the EZB web server, then configure WiFi client mode with your router SSID and password. Restart EZB and confirm it gets a LAN IP.
  • Docs: EZB v4 WiFi / web config info: https://synthiam.com/Support/Hardware/EZ-B-v4 and WiFi troubleshooting docs: https://synthiam.com/Support/troubleshooting/Troubleshoot-WiFi-Connections
  1. If EZB must remain in AP mode and you must use two WiFi adapters on the PC: Option A - Set interface metrics so the Internet adapter remains default
  • Give the Internet adapter a higher priority (lower metric) and the EZB adapter a lower priority (higher metric). Windows will keep your Internet as the default gateway while still allowing direct traffic to the EZB network.
  • Commands (run in an elevated Command Prompt):
    1. List interfaces and index: netsh interface ipv4 show interfaces
    2. Set metric for internet adapter (example name "WiFiInternet"): netsh interface ipv4 set interface "WiFiInternet" metric=10
    3. Set metric for the EZB adapter (example name "WiFiEZB"): netsh interface ipv4 set interface "WiFiEZB" metric=200
  • Note: On some Windows installs the GUI "automatic metric" needs to be disabled per adapter (Network Connections right click adapter Properties IPv4 Advanced uncheck "Automatic metric" and set manual metric).

Option B - Assign a static IP to the EZB adapter and add a persistent route to EZB

  • This avoids the EZB adapter setting a default gateway that steals internet traffic.
  • Steps:
    1. Connect to the EZB AP.
    2. In Network Connections right-click the EZB adapter IPv4 Properties set:
      • IP: 192.168.1.2
      • Mask: 255.255.255.0
      • Gateway: (leave blank)
      • DNS: leave blank (or your normal DNS)
    3. Add a route so your PC knows to reach 192.168.1.1 (EZB) via that adapter. First find the interface index: netsh interface ipv4 show interfaces (note the idx number for the EZB adapter)
    4. Add persistent route (replace ifidx with the idx from prior step): route add 192.168.1.1 mask 255.255.255.255 192.168.1.2 if ifidx -p Example: route add 192.168.1.1 mask 255.255.255.255 192.168.1.2 if 12 -p
  • This keeps your default gateway pointing to the internet dongle while still letting you reach the EZB at 192.168.1.1.

Why Option B is effective: If the EZB network gives the PC a default gateway, Windows may route all traffic through it (and there’s no internet there). Setting no gateway on that adapter prevents it from becoming the default route; the static route ensures the EZB is still reachable.

  1. Alternative hardware solutions (if Windows tricks are too finicky)
  • Use a small travel router or Raspberry Pi as a bridge between the EZB AP and your internet network.
  • Use a USBEthernet or USBserial connection to the EZB (connect the EZB to your PC via USB serial if available). That removes WiFi from the equation entirely.
  • Use the EZB in client mode to your phone hotspot (if you can provide a stable hotspot with the dongle).
  1. Workarounds in ARC / skill strategy
  • Split tasks across devices: run internetreliant AI skills (PandoraBot) on a separate machine/phone (they talk to ARC via network or middleware), while ARC runs the robot control locally.
  • Add a simple network watch script to your merged EZB_D22 monitor: when the PC loses internet, pause the PandoraBot skill (controlCommand("PandoraBot","ScriptStop")) and resume when internet returns. I can provide this script if you want that behavior.

Quick checklist you can try now

  • Question: Is your EZB in AP mode (you connect to an SSID from the EZB) or in client mode on your router? (Reply with that.)
  • If AP mode and you want to keep it that way, try Option B (static IP / persistent route). Tell me your Windows version and the adapter names you see from netsh and I’ll give exact commands to paste.
  • If you can change EZB to client mode, I recommend that - it typically resolves all stability problems.

If you want, I’ll:

  • Provide exact netsh commands for your setup - tell me netsh interface ipv4 show interfaces output (or your adapter names).
  • Provide stepbystep screenshots text for setting a static IP and route on Windows 10/11.
  • Add a small ARC JavaScript snippet that pauses PandoraBot when internet is down and restarts when internet returns.

Which do you want to try first - set EZB to client mode, or I give the static IP + route steps for your current AP + twoadapter setup?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.