Switch a LED on from OpenSim
Three years ago I published this video:
And some people asked to me for a 'How to' … and well … here we go!
Arduino part
We need a Arduino. In this case I’m using a Arduino Wifi Shield.
This is all the code you will need.
With te Serial Monitor of the Arduino you can see if you are connected to the Wifi and what is your IP.
You can test if everything is working fine with curl
# Low the LED
curl http://192.168.0.21/L
# Hight the LED
curl http://192.168.0.21/H
OpenSim part
How to install:
wget http://opensimulator.org/dist/opensim-0.9.0.0.tar.gz
cd opensim-0.9.0.0/bin
Then if you try to start opensim you will recieve this warning:
./opensim.sh: 5: ./opensim.sh: mono: not found
Let’s install Mono dependencies:
apt-get install mono-complete
And start again with:
./opensim.sh
First question is about region.
Create a user with the command 'create user'.
IMPORTANT: If you fill First with 'moncho' and Last with 'pena' your user id will be 'moncho pena'.
Singularity
You can use another 'Second Life' Client but in this sample I’m using Singularity.
Thiis is the configuration of the grid.
How to login:
Ok. You are in a virtual world an you now are like a god. Create a new object. Then select, click on the tab Content and New Script.
This is the code where we are calling the “webhook” of the Arduino. We change the texture of the object everytime we touch it and we do the call to switch the led.
string texture1 = "00000000-0000-2222-3333-100000001041";//UUID of texture 1 (or inventory name if in inventorY)
string texture2= "00000000-0000-1111-9999-000000000003";//UUID of texture2
float time = 0.0;//time to sleep in seconds
integer side = ALL_SIDES;//which side to change texture on
string URL = "http://192.168.0.21";
string HTTP_USER_AGENT = "HTTP_USER_AGENT";
switch(string texture)
{
llSetTexture(texture, side);
currentstate = ~currentstate;//swith states
llSleep(time);
}
default
{
touch_start(integer total_number)
{
if(currentstate) {
switch(texture1);
llHTTPRequest(URL + "/H", [], "" );
llSay(0, "On");
} else {
switch(texture2);
llHTTPRequest(URL + "/L", [], "" );
llSay(0, "Off");
}
}
}
Now if you click the object you will see a warning icon like this:
This is why you have to allow to connect OpenSim to the Arduino Shield IP. Go to the 'OpenSim.ini' and add this line:
OutboundDisallowForUserScriptsExcept = 192.168.0.21
This a new video with this sample working:
Maybe OpemSim is not a fashionable application but is fine to do tests.