Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Database SlPhant  

SlPhant

A simple external database for SL

Category: Database
By : SLPhant
Created: 2014-09-24 Edited: 2014-09-24
Worlds: Second Life

the Zip file

Download all files for SlPhant
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 // See https://data.sparkfun.com/
2
3 // SLPhant_v1_0.lsl
4 // *****************************************************************************************
5 // SLPhant v1.0 Header
6 // *** Enter Public/Private/Delete Keys below *** //
7 string sSLPHANT_PUBLIC_KEY = "7JvgN1NbE5H2JwAvlza0";
8 string sSLPHANT_PRIVATE_KEY = "mzqm6g6GNaS0q6D7RrNy";
9 // Save your Delete Key here so you never lose it "xxxxxxxxxxxxxxxxxxxx";
10
11 // *** Enter your Field Names below (Case Sensitive!) in SAME ORDER as Phant Returns *** //
12 // *** For Example: list lSLPHANT_FIELDNAMES { Id, Temperature, Pressure, Humidity, WindSpeed };
13 //list lSLPHANT_FIELDNAMES = [ "avatarname", "id", "regionname" ];
14
15 // *** If running your own Phant Server, enter URL below *** //
16 string sSLPHANT_BASE_URL = "https://data.sparkfun.com/";
17
18 // SLPhant Data Formats (must begin w/ a period ".")
19 string sSLPHANT_FORMAT_CSV = ".csv";
20 string sSLPHANT_FORMAT_JSON = ".json";
21 string sSLPHANT_FORMAT_SQL = ".sql";
22 string sSLPHANT_FORMAT_PSQL = ".psql";
23 string sSLPHANT_FORMAT_ATOM = ".atom";
24 // string sSLPHANT_FORMAT_xxxx = "."; // Place holder for future formats
25 // *****************************************************************************************
26 key SLPhant_Clear() {
27 // Clear All Data: http://data.sparkfun.com/input/PUBLIC_KEY/clear?private_key=PRIVATE_KEY
28 return llHTTPRequest(sSLPHANT_BASE_URL+"input/"+sSLPHANT_PUBLIC_KEY+"/clear?private_key="+sSLPHANT_PRIVATE_KEY, [], "");
29 }
30 // *****************************************************************************************
31 // It is *YOUR* responsibility to have sData in format "Field1=Value1&Field2=Value2..."
32 // Fields must be the valid names for YOUR stream.
33 // Values must be put thru llEscapeURL(sURL).
34 // Name/Value pairs must be separated by "&".
35 //
36 // *** For example...
37 // SLPhant_AddData(
38 // "avatarname="+llEscapeURL(llKey2Name(llGetOwner()))+
39 // "&id="+llEscapeURL(llGetOwner())+
40 // "®ionname="+llEscapeURL(llGetRegionName()));
41 key SLPhant_AddData(string sData) {
42 // Add Data: http://data.sparkfun.com/input/PUBLIC_KEY?private_key=PRIVATE_KEY&FIELD1=VALUE1&=FIELD2=VALUE2
43 return llHTTPRequest(sSLPHANT_BASE_URL+"input/"+sSLPHANT_PUBLIC_KEY+"?private_key="+sSLPHANT_PRIVATE_KEY+"&"+sData, [], "");
44 }
45 // *****************************************************************************************
46 key SLPhant_RequestData(string sFormat) {
47 // Get Data: http://data.sparkfun.com/output/PUBLIC_KEY.FORMAT?page=PAGE_NUMBER
48 return llHTTPRequest(sSLPHANT_BASE_URL+"output/"+sSLPHANT_PUBLIC_KEY+sFormat, [], "");
49 }
50 // *****************************************************************************************
51 key SLPhant_RequestStats(string sFormat) {
52 // Get Stats: http://data.sparkfun.com/output/PUBLIC_KEY/stats.FORMAT
53 return llHTTPRequest(sSLPHANT_BASE_URL+"output/"+sSLPHANT_PUBLIC_KEY+"/stats"+sFormat, [], "");
54 }
55 // *****************************************************************************************
56 // *****************************************************************************************
57 // *****************************************************************************************
58 //
59 // Copy everything above this line to your own Program.
60 // Then modify the Key Constants to use your own Stream's Keys.
61 //
62 // *****************************************************************************************
63 // *****************************************************************************************
64 // *****************************************************************************************
65 //
66 // Example Program...
67 //
68 integer iTestNumber = 0;
69 key kSLPhantHttpRequest = NULL_KEY;
70
71 default {
72 // *****************************************************************************************
73 state_entry() {
74 iTestNumber = 0;
75 llOwnerSay("Test "+(string)iTestNumber+": Clearing Data...");
76 kSLPhantHttpRequest = SLPhant_Clear();
77 }
78 // *****************************************************************************************
79 http_response(key kRequestId, integer iStatus, list lMetadata, string sBody) {
80 llOwnerSay("http_response("+(string)kRequestId+", "+(string)iStatus+", ["+llList2CSV(lMetadata)+"], "+sBody+")");
81 if(kRequestId==kSLPhantHttpRequest) {
82 llSleep(1.0); // Phant sometimes messes up if polled too fast.
83 if(iTestNumber==0) {
84 iTestNumber++;
85 llOwnerSay("Test "+(string)iTestNumber+": Adding Data...");
86 kSLPhantHttpRequest = SLPhant_AddData("avatarname="+llEscapeURL(llKey2Name(llGetOwner()))+"&id="+llEscapeURL(llGetOwner())+"®ionname="+llEscapeURL(llGetRegionName()));
87 } else if(iTestNumber==1) {
88 iTestNumber++;
89 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in Default Format...");
90 kSLPhantHttpRequest = SLPhant_RequestData("");
91 } else if(iTestNumber==2) {
92 iTestNumber++;
93 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in "+sSLPHANT_FORMAT_CSV+" Format...");
94 kSLPhantHttpRequest = SLPhant_RequestData(sSLPHANT_FORMAT_CSV);
95 } else if(iTestNumber==3) {
96 iTestNumber++;
97 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in "+sSLPHANT_FORMAT_JSON+" Format...");
98 kSLPhantHttpRequest = SLPhant_RequestData(sSLPHANT_FORMAT_JSON);
99 } else if(iTestNumber==4) {
100 iTestNumber++;
101 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in "+sSLPHANT_FORMAT_SQL+" Format...");
102 kSLPhantHttpRequest = SLPhant_RequestData(sSLPHANT_FORMAT_SQL);
103 } else if(iTestNumber==5) {
104 iTestNumber++;
105 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in "+sSLPHANT_FORMAT_PSQL+" Format...");
106 kSLPhantHttpRequest = SLPhant_RequestData(sSLPHANT_FORMAT_PSQL);
107 } else if(iTestNumber==6) {
108 iTestNumber++;
109 llOwnerSay("Test "+(string)iTestNumber+": Requesting Data in "+sSLPHANT_FORMAT_ATOM+" Format...");
110 kSLPhantHttpRequest = SLPhant_RequestData(sSLPHANT_FORMAT_ATOM);
111 } else if(iTestNumber==7) {
112 iTestNumber++;
113 llOwnerSay("Test "+(string)iTestNumber+": Requesting Stats in "+sSLPHANT_FORMAT_JSON+" Format...");
114 kSLPhantHttpRequest = SLPhant_RequestStats(sSLPHANT_FORMAT_JSON);
115 } else {
116 llOwnerSay("Done. You can view your data at "+sSLPHANT_BASE_URL+"streams/"+sSLPHANT_PUBLIC_KEY);
117 }
118 }
119 }
120 // *****************************************************************************************
121 }
122 // *****************************************************************************************

Back to the Best Free Tools in Second Life and OpenSim.