I have a JavaScript in ARC that go onto the Internet and retrieves a full weather report from a Weather service, parses information out of the returned file and has the robot speak the information
For Example: A section of my ARC Setup INT script will set the variable $OutsideTemp to "1" and then a ControlCommand will start a separate JavaScript that will run the above mentioned procedure. The INT script will then pause. Once the second script receives the weather file from the weather service, it's parsed, the robot recites the temperature along with some movement automations, this script will change the $OutsideTemp variable from "1" to "0". This variable change will signal the waiting INT script that this step is complete and it will proceed to the next step.
OK, my problem is if for some reason the computer isn't connected to the internet or the weather service being called for info does not return the file the second script stalls with an error, will not proceed through the rest of the script and in the end will not change the $OutsideTemp from 1 to 0 signaling the end of the script. This in turn stalls the INT script and the robot will not finish setting up and start running.
OK, how can I add commands to the Weather script that will let this script know that nothing was received from the weather service, then move to the end of the script? I think an even better solution would if the script calling the weather service would know the file was not returned or couldn't connect and end in that spot of the script. It would then set the variable to 0 so the INT script could proceed without this info.
I'll post my scripts below so I can get informed advice. I'm open to all advice, rewrites or constructive criticism. Thanks!
Here's the part of my INT script that calls the temp from the weather service:
//Temp
//---------------
ControlCommand("Head Section", "ScriptStart", "Bubble Full Down");
setVar( "$OutsideTemp", 1 ); //Sets Varaible so Script will run
ControlCommand("Time, Date & Temp", "ScriptStart", "Outside Temp");
while (getVar("$OutsideTemp")== 1) { //Pause script for Temp report
sleep(100);
}
Here's my script that calls the weather service files, parses it and has the robot speak it:
ControlCommand("Personality Generator", "PauseOn");
//Start anamation //---------------------------- setVar( "$OutsideTemp", 1 ); //Sets Varaible so Script will run PWM.set(D0, 70); //Start Ear Motors PWM.set(D9, 20); //Start Crown Motor ControlCommand("Head Section", "ScriptStart", "Radar 1/4 Sweep"); ControlCommand("Left Arm", "ScriptStart", "Left Claw Open"); ControlCommand("Right Arm", "ScriptStart", "Right Claw Closed");
//Get weather conditions from openweathermao.org var url1 = "https://api.openweathermap.org/you dont need to see this part. HAHA" var content = Net.hTTPGet(url1);
//Read Tempture //--------------- pos = 0; beginPos = pos; pos = content.indexOf("temp", beginPos); endPos = pos; otherend = content.indexOf(",",endPos); var temp = content.substring((endPos+6),(otherend)); //temp = (temp*1.8)-459.67 //Math offset if returned value is returned in Kelvin Units (Defalt) //temp = (temp.toFixed(1)) //Math offset if returned value is returned in Kelvin Units (Defalt)
//Round temp returned to whole number //----------------------------------- var tempRound = Math.round(temp) print("Temperature Rounded: " + tempRound);
controlCommand("Phrases", "Track_17"); //Say "The Temp is at"
sleep(1750)
//**************** //this block extracts numbers out of tempRound Variable where the temp is stored // and places each digit into it's own variable so orbot can speak each digit. //****************
// Convert the number to a string
var numberString = tempRound.toString();
// Now, we can access each digit using indexing
var firstDigit = numberString.charAt(0); // First Digit
var secondDigit = numberString.charAt(1); // Second Diget
var thirdDigit = numberString.charAt(2); // Third Digit if needed
// Now we can use firstDigitNumber and secondDigitNumber as needed
Console.log(firstDigit); // Outputs first digit Console.log(secondDigit); // Outputs second digit
//Say first digit in temp, 20 - 90 //-------------------------------- if (firstDigit == 2) { ControlCommand("Numbers", "Track_20"); //Say 20" sleep(1250); } else if (firstDigit == 3) { ControlCommand("Numbers", "Track_21"); //Say 30" sleep(1300); } else if (firstDigit == 4) { ControlCommand("Numbers", "Track_22"); //Say 40" sleep(1350); } else if (firstDigit == 5) { ControlCommand("Numbers", "Track_23"); //Say 50" sleep(1300); } else if (firstDigit == 6) { ControlCommand("Numbers", "Track_24"); //Say 60" sleep(1400); } else if (firstDigit == 7) { ControlCommand("Numbers", "Track_25"); //Say 70" sleep(1400); } else if (firstDigit == 8) { ControlCommand("Numbers", "Track_26"); //Say 80" sleep(1350); } else if (firstDigit == 9) { ControlCommand("Numbers", "Track_27"); //Say 90" sleep(1400); }
//Say second digit in temp, 1 - 9
//--------------------------------
if (secondDigit == 0) {
ControlCommand("Phrases", "Track_3"); //Say "Degrees Fahrenheait"
sleep(1900);
//controlCommand("Phrases", "Track_12"); //Say "On this Alien Planet"
//sleep(2000);
PWM.set(D0, 0); //Start Ear Motors
PWM.set(D9, 0); //Start Crown Motor
setVar( "$OutsideTemp", 0 ); //Clears Varaible so next Script will run
halt();
} else if (secondDigit == 1) {
ControlCommand("Numbers", "Track_1"); //Say "1"
sleep(1350);
} else if (secondDigit == 2) {
ControlCommand("Numbers", "Track_2"); //Say "2"
sleep(1250);
} else if (secondDigit == 3) {
ControlCommand("Numbers", "Track_3"); //Say "3"
sleep(1400);
} else if (secondDigit == 4) {
ControlCommand("Numbers", "Track_4"); //Say "4"
sleep(1450);
} else if (secondDigit == 5) {
ControlCommand("Numbers", "Track_5"); //Say "5"
sleep(1450);
} else if (secondDigit == 6) {
ControlCommand("Numbers", "Track_6"); //Say "6"
sleep(1450);
} else if (secondDigit == 7) {
ControlCommand("Numbers", "Track_7"); //Say "7"
sleep(1400);
} else if (secondDigit == 8) {
ControlCommand("Numbers", "Track_8"); //Say "8"
sleep(1400);
} else if (secondDigit == 9) {
ControlCommand("Numbers", "Track_9"); //Say "9"
sleep(1450);
}
//Shut down anamations //--------------------------------------------------------------- ControlCommand("Phrases", "Track_3"); //Say "Degrees Fahrenheait" sleep(1900) //controlCommand("Phrases", "Track_12"); //Say "On this Alien Planet" PWM.set(D0, 0); //Start Ear Motors PWM.set(D9, 0); //Start Crown Motor setVar( "$OutsideTemp", 0 ); //Clears Varaible so next Script will run
ControlCommand("Personality Generator", "PauseOff"); ControlCommand("Script Manager", "ScriptStart", "Both Claws Rest Closed");

OK, Thanks! Your new wind speed script seems to be working nicely in my robot.
To answer your question, Yes, please redo my Humidly script to use the same speakNumber() helper and JSON parsing. That was going to be my next ask. I haven't tried the last Humidly script you did for me but I'm sure it will need the same treatment. @Athena, Can you please proceed with the new Humidly script you offered?
Perfect - I’ll refactor the Humidity script to use the same robust pattern and the speakNumber() helper you’re using for Wind Speed. This script:
Replace YOUR_API_KEY in the url with your actual OpenWeather API key. Confirm your soundboard/skill names are exactly as used here ("Soundboard 2", "Soundboard v4", "Numbers", "Phrases") - if they differ, change the strings.
Script - drop into a Script skill (JavaScript):
Notes and tips
Want me to:
Which would you prefer?
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.
I found a problem with both the Wind speed and the Humidity script you helped me with.
Everything runs well until it gets to the speakNumber() function block on each. If the number it needs to call from the Numbers Soundboard is above 29 the script will stall and throw an error that the track wanted does not exist. Once I clear the error window the "ones" number will play abd the script will finish. For example, if the humidity is "87 percent" the script will stop and not play the track that says "80" and throw an error window saying the track "80" can't be found. I'll clear the window, the script will start up on it's own and play the sound file that says "7".
I think it's because my sound files that say the numbers, 30,40,50,60,70,80 and 90 are not in the numbered slots that correspond with the number sound. 30 is not in the 30 slot, 40 is not in the 40 slot and so on. Here's the if/else if section from my old working script that show the proper Numbers Soundboard slots where these sound files are found:
if (firstDigit == 2) { ControlCommand("Numbers", "Track_20"); //Say "20" } else if (firstDigit == 3) { ControlCommand("Numbers", "Track_21"); //Say "30" } else if (firstDigit == 4) { ControlCommand("Numbers", "Track_22"); //Say "40" } else if (firstDigit == 5) { ControlCommand("Numbers", "Track_23"); //Say "50" } else if (firstDigit == 6) { ControlCommand("Numbers", "Track_24"); //Say "60" } else if (firstDigit == 7) { ControlCommand("Numbers", "Track_25"); //Say "70" } else if (firstDigit == 8) { ControlCommand("Numbers", "Track_26"); //Say "80" } else if (firstDigit == 9) { ControlCommand("Numbers", "Track_27"); //Say "90" }
Is it possible for you to fix the humidity script you just wrote to reflect these 10's numbers file locations?
Perfect - I updated the Humidity script so the tens (20,30,40...90) use the exact Numbers soundboard slots you showed (20Track_20, 30Track_21, , 90Track_27). The speakNumber() helper now uses a lookup table for tens so it won't try to play Track_30/40/etc. and throw that error.
Drop this into a Script skill (Javascript). Replace YOUR_API_KEY with your key and confirm the soundboard/skill names exactly match your project. I kept the same error verbal cues (Soundboard 2 Track_26 then Soundboard v4 Track_20) and the cleanup behavior that sets $Humid back to "0".
Testing tips
Would you like me to apply this same tens-track mapping to the Wind Speed script too (so both scripts match exactly)? I can paste the updated Wind script if you want.
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.
The last Humidity script you helped me with seems to work correctly and as needed.
@Athena , Could you please update and apply this same tens-track mapping to the last Wind Speed script too (so both scripts match exactly)?
Great - thanks for the details, Dave. I updated the Wind Speed script to use the same tens-track mapping as the Humidity script so it will call the exact Numbers soundboard slots you showed (20 Track_20, 30 Track_21, 90 Track_27). The script also keeps the robust JSON parsing, timeout, internet check, and error handling (plays "Not" then "Active" and always clears the $WSpeed flag so your INT script never stalls).
Drop this into a Script skill (JavaScript). Replace YOUR_API_KEY in the URL with your key and confirm the skill & track names match your project ("Soundboard 2", "Soundboard v4", "Numbers", "Phrases"). If any names differ, tell me the exact names and I’ll update the calls.
Notes and tips
Would you like me to:
Which would you prefer?
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.
Athena , Yes, this last windspeed script runs as expected. However I won't truly know until the wind gets above 30 mph and I make the call.
Next, the Open Weather Map API sends the temperature and windspeed in a fraction. For example 85.71 or 7.91. This is why I designed this script to round the returned value to the nearest whole number. These scripts as rewritten by you only show (print) the rounded number in the debug window of the script. However along with the rounded number I still want to see the number before it's rounded with their fractional numbers. What would the print(); command look like and where in these two scripts can I place it so the entire returned number with it's decimal will show in the debug window?
Perfect - easy tweak. Add a debug print right after the scripts extract the raw numeric value and before you round it. Use print() (not console.log()) and toFixed() if you want a fixed number of decimal places.
Below are the exact places and example lines to insert into each script.
Wind Speed
Humidity
Where exactly to put them in your current scripts
Notes and tips
Want me to paste the exact lines into the full wind and humidity scripts (with the correct insertion points) so you can copy/paste the complete updated scripts back into ARC?
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.