Robot Not a Dev? Buy Now
Not a Dev?

Misty Community Forum

Triggering a Misty Skill using the bump sensors

I’m trying to trigger an external API call after mistys bumpers are pressed. My code is here. The robot doesn’t seem to respond to me pressing any bumpers.

I modeled my code to do this after this example. I’m not sure what I’m doing wrong. Any tips would be helpful. Thanks!

Thanks for sharing this @edensjasmine. Can you also send us your log files (you can send them to my email or to support@)?

Hey - I figured it out. This API called doesn’t work when I use a variable like this:

misty.SendExternalRequest( "GET", yesnoURL);

The code only works when I put in the string like this:

misty.SendExternalRequest( "GET", "https://yesno.wtf/api");
2 Likes

I’m glad you solved this. We’ll make sure to get that noted to clear up future confusion.

1 Like

For SendExternalRequest, I would expect you to be able to pass in a variable for the URL argument, as long as the value assigned to that variable is the correct type. Although there are a couple of caveats around defining global vars in JavaScript skills. If you don’t mind sharing it’d be interesting to see the version of your skill code that used the variable, rather than the string.

1 Like

I thought the same thing. I’m a javascript n00b so maybe I should’ve used var instead of let but let me know what you discover.

My non-working code is linked in my original post. My working code is here.

2 Likes

Thanks!

I noticed a couple of things that may help. First, on lines 35 - 37, the property test and return property are assigned to an event named “BumpSensor”, but the name of the registered event listener is “checkedWeather”:

misty.AddPropertyTest("BumpSensor", "isContacted", "==", true, "boolean");
misty.AddReturnProperty("BumpSensor", "sensorName");
misty.RegisterEvent("checkWeather", "BumpSensor", 200, true);

In order to attach the test and the return property to the correct listener, the value for eventName in misty.AddReturnProperty() and misty.AddPropertyTest() must be the same as the eventName passed into misty.RegisterEvent(). (It’s easy to mix this up with the messageType argument – messageType must match one of Misty’s event types, but you can name the listener for those events whatever you like.) You might try something like this instead:

misty.AddPropertyTest("checkWeather", "isContacted", "==", true, "boolean");
misty.AddReturnProperty("checkWeather", "sensorName");
misty.RegisterEvent("checkWeather", "BumpSensor", 200, true);

Second, when you instantiate a global variable in a Misty skill, it’s best to use the syntax below:

_globalVar = "Event callbacks can access this string!"

This syntax is idiosyncratic to Misty’s JavaScript SDK. With Misty’s JavaScript engine, callback functions create a new thread that doesn’t always have access to the global variables you set with var, const, or let. (You can also use misty.Set() to save a key/value pair to Misty’s database for use across skills).

If you change let yesnoURL = "https://yesno.wtf/api" to
_yesnoURL = "https://yesno.wtf/api", you should get better results.

I tested those changes in the gist shared here, and Misty was able to access the endpoint and print the results to the Skill Runner console :slight_smile:

1 Like

I didn’t know we could do this @johnathan! Thanks for calling this out.

1 Like