ExampleHomeAlarmSystem
De DigiWiki.
(Page créée avec « The code is licensed under LGPL: that is, you can use it for any purpose, but you should acknowledge the author in the sources. Comments: ruben@rubenkleiman.com This code t… ») |
|||
Ligne 36 : | Ligne 36 : | ||
Follow these steps in order: | Follow these steps in order: | ||
- | 1 | + | 1 Copy the contents of the following LSL script to an object located in your property: |
http://home.earthlink.net/~kleiman/examples/home_alarm04_script.txt | http://home.earthlink.net/~kleiman/examples/home_alarm04_script.txt | ||
- | 2 | + | 2 Enable the script by touching the object (follow object's instructions); disable it by touching it again. |
The alarm object in SL should acknowledge that it started (chat message). | The alarm object in SL should acknowledge that it started (chat message). | ||
- | 3 | + | 3 When the alarm starts, you will get a chat message with the alarm's monitoring channel key. Copy and |
paste it so that you can use it in step 6, below. | paste it so that you can use it in step 6, below. | ||
- | 4 | + | 4 Copy the contents of the html code in http://home.earthlink.net/~kleiman/examples/home_alarm04_html.txt |
into a text file in your computer, save it with an .html extension, | into a text file in your computer, save it with an .html extension, | ||
and open it in Internet Explorer. Save it in Notepad (Windows), | and open it in Internet Explorer. Save it in Notepad (Windows), | ||
but not in a word processing program like Word. | but not in a word processing program like Word. | ||
- | 5 | + | 5 Open the HTML page. |
- | + | 5a If the Internet Explorer banner at the top of the page asks you whether | |
to allow an ActiveX control to run, click on the banner message and select | to allow an ActiveX control to run, click on the banner message and select | ||
"Allow Blocked Content..." I use a standard ActiveX component that lets your | "Allow Blocked Content..." I use a standard ActiveX component that lets your | ||
browser communicate with the Second Life server (and thus to your script). | browser communicate with the Second Life server (and thus to your script). | ||
- | + | 5b Ensure that cookies are enabled in your browser or else accept cookies from the page. | |
I use a cookie to save your configuration information. | I use a cookie to save your configuration information. | ||
- | 6 | + | 6 Enter the alarm system key (see step 3, above) into the "Channel Key" |
field in the "Alarm Configuration Settings" sections of the page. | field in the "Alarm Configuration Settings" sections of the page. | ||
The setting will take effect once you out of the field. | The setting will take effect once you out of the field. | ||
(Right now, the only way to go back to the default settings is | (Right now, the only way to go back to the default settings is | ||
to remove the alarm system's cookie.) | to remove the alarm system's cookie.) | ||
- | 7 | + | 7 On the web browser, click on the "Start" button to start monitoring from your browser location. |
Your should immediately see status information and you will get results in a few | Your should immediately see status information and you will get results in a few | ||
seconds. Wait 20 seconds. In version 0.4, the browser will poll the home alarm system every 20 seconds | seconds. Wait 20 seconds. In version 0.4, the browser will poll the home alarm system every 20 seconds | ||
Ligne 64 : | Ligne 64 : | ||
(being nice to the poor little overworked SL servers out there). | (being nice to the poor little overworked SL servers out there). | ||
Some debugging information from your SL alarm object may from time to time show up as chat. | Some debugging information from your SL alarm object may from time to time show up as chat. | ||
- | 8 | + | 8 Until the 1.0 release, I urge you not to change the configuration settings |
other than the alarm's monitoring channel key, as necessary. | other than the alarm's monitoring channel key, as necessary. | ||
If you change any settings, some may not work as expected or your alarm | If you change any settings, some may not work as expected or your alarm |
Version du 11 mars 2012 à 05:06
The code is licensed under LGPL: that is, you can use it for any purpose, but you should acknowledge the author in the sources.
Comments: ruben@rubenkleiman.com
This code teaches you how to monitor your Second Life home using a web browser. A server is not necessary. In addition, as people ask me questions, I will add information on useful variations on this code in the Variations On The Theme section at the end of this page.
Pre-requisites: Basic familiarity with LSL language and with DHTML.
The code for this tutorial consists of two files:
I provide you with (read Instructions below to access them):
- A ready-to-run, SL script that you can attach to any SL object in your Second Life property.
- An HTML page that communicates with the SL script.
Please carefully read the instructions in this page before asking me any questions. This is not a trivial application. Thanks!
IMPORTANT 1: Until version 1.0 is released, some of the functionality will be turned on or off, but the main system will function. Documentation will be available in version 1.0. Until then, the code documentation are meaningful variable and function names and some comments. Please do not contact me unless you have carefully read the instructions in this page (thanks!).
IMPORTANT 2: This works only in Internet Explorer right now. An ActiveX object is used to communicate via XML-RPC: you must unblock it if your IE browser blocks it (the default). I'll change it to work with other browsers when I have the time; the only issue is the different way Mozilla-based browsers handle certification.
Instructions
Follow these steps in order:
1 Copy the contents of the following LSL script to an object located in your property: http://home.earthlink.net/~kleiman/examples/home_alarm04_script.txt 2 Enable the script by touching the object (follow object's instructions); disable it by touching it again.
The alarm object in SL should acknowledge that it started (chat message).
3 When the alarm starts, you will get a chat message with the alarm's monitoring channel key. Copy and
paste it so that you can use it in step 6, below.
4 Copy the contents of the html code in http://home.earthlink.net/~kleiman/examples/home_alarm04_html.txt
into a text file in your computer, save it with an .html extension, and open it in Internet Explorer. Save it in Notepad (Windows), but not in a word processing program like Word.
5 Open the HTML page.
5a If the Internet Explorer banner at the top of the page asks you whether to allow an ActiveX control to run, click on the banner message and select "Allow Blocked Content..." I use a standard ActiveX component that lets your browser communicate with the Second Life server (and thus to your script). 5b Ensure that cookies are enabled in your browser or else accept cookies from the page. I use a cookie to save your configuration information.
6 Enter the alarm system key (see step 3, above) into the "Channel Key"
field in the "Alarm Configuration Settings" sections of the page. The setting will take effect once you out of the field. (Right now, the only way to go back to the default settings is to remove the alarm system's cookie.)
7 On the web browser, click on the "Start" button to start monitoring from your browser location.
Your should immediately see status information and you will get results in a few seconds. Wait 20 seconds. In version 0.4, the browser will poll the home alarm system every 20 seconds This is a configurable setting. (being nice to the poor little overworked SL servers out there). Some debugging information from your SL alarm object may from time to time show up as chat.
8 Until the 1.0 release, I urge you not to change the configuration settings
other than the alarm's monitoring channel key, as necessary. If you change any settings, some may not work as expected or your alarm system might crash due to problem described in Known Problems, below.
Have fun! - Ruben
Troubleshooting
1. Have you followed the steps in the instructions in the right order? 2. Are you sure that you started the alarm? The alarm will give
you a message when it starts. Touch it again if you are not sure.
3. Are you sure that the alarm key that you entered in your
browser is the same as the home alarm's key?
4. Have you limited your monitoring to one browser at a time? 5. Are you not sure that your Internet Explorer page is
properly initialized? Start Internet Explorer and delete all cookies (Tools -> Internet Options); then open the alarm system page again and enter the monitoring channel key. (If you want to manually delete just the alarm system cookie, its name starts with _rk_.)
6. Nothing happens? Make sure that you have started the alarm system object in SL
and that you have clicked the "Start Monitoring" button in the web browser page. Look at your chat messages in SL to make sure that your alarm object is healthy (it will tell you if/when it crashes).
Known Problems
1. If the number of sensed objects is large, you will get a stack heap crash.
The default configuration settings will minimize but not necessarily eliminate this possibility.
2. Changing configuration settings may precipitate problem #1.
Variations On The Theme
Is it possible to send binary data to the SL server?
In theory, yes. In practice, you need to be aware that:
(1) Data is marshalled in XML, which is based on a character set rather than on a binary format.
(2) The file size of an XML file accepted by the SL server is arbitrary; we have no control over it.
Solution:
(1) Binary format: Pack and unpack your binary file data into a format that will survive the network and transport layers. One such format is Base64. On the HTML page, use Javascript to marshall the binary data into a Base64 string. Similarly, on the SL script side, change it to convert the received (Base64) string into binary using llBase64ToInteger. What you do with the binary data is up to you from here on.
(2) File size: experiment with increasingly large file sizes until you get an error. That will tell you the actual maximum file size.