|
|
|
The following page was printed from RemoteCentral.com:
Topic: | Weather station This thread has 14 replies. Displaying all posts. |
|
Post 1 made on Sunday December 23, 2007 at 07:58 |
Hi All, I have build my own weather station with some help from snelvuur.
I was wondering if some can help me to optimize the code script will grab some date from my Homeseer web page
++++++++++++++++++++++++ //var start = 0; //var result = ""; var socket = new TCPSocket(false);
socket.onConnect = function() { // System.print("OnConnect"); socket.write("GET /rover.asp?show=locWeer&options=10100010000000 HTTP/1.0\r\n"); socket.write("Accept: */*\r\n"); socket.write("Host: 192.168.1.100\r\n"); socket.write("\r\n"); };
socket.onData = function() { result += socket.read(3000,1000);
start = result.indexOf(" result = result.substring(start,result.length); // Js Temp t1 = result.indexOf("Js Temp",start)+24; t2 = result.indexOf("C<\/",t1)+1; // event1 = result.substring(t1,t2); CF.widget("jstemp").label=result.substring(t1,t2);
// Js Hygro h1 = result.indexOf("Js Hygro",start)+25; h2 = result.indexOf("H.<\/",h1)+2 hygro1 = result.substring(h1,h2); CF.widget("jshygro").label=result.substring(h1,h2);
// Buiten Temp t4 = result.indexOf("Buiten Temp",start)+24; t5 = result.indexOf("C<\/",t4)+1; descrip1 = result.substring(t4,t5); CF.widget("buitentemp").label=result.substring(t4,t5);
// Buiten Hygro h4 = result.indexOf("Buiten Hygro",start)+25; h5 = result.indexOf("H.<\/",h4)+2; hdescrip1 = result.substring(h4,h5); CF.widget("buitenhygro").label=result.substring(h4,h5);
// Slapkamer Temp t6 = result.indexOf("Slaapkamer Temp",start)+28; t7 = result.indexOf("C<\/",t6)+1; descrip2 = result.substring(t6,t7); CF.widget("slaapkamertemp").label=result.substring(t6,t7);
// Slaapkamer Hygro h6 = result.indexOf("Slaapkamer Hygro",start)+29; h7 = result.indexOf("H.<\/",h6)+2; hdescrip2 = result.substring(h6,h7); CF.widget("slaapkamerhygro").label=result.substring(h6,h7);
// Woonkamer Temp t8 = result.indexOf("Woonkamer Temp",start)+27; t9 = result.indexOf("C<\/",t8)+1; descrip2 = result.substring(t8,t9); CF.widget("woonkamertemp").label=result.substring(t8,t9);
// Woonkamer Hygro h8 = result.indexOf("Woonkamer Hygro",start)+28; h9 = result.indexOf("H.<\/",h8)+2; hdescrip2 = result.substring(h6,h9); CF.widget("woonkamerhygro").label=result.substring(h8,h9);
// Baby Temp t10 = result.indexOf("Baby Temp",start)+22; t11 = result.indexOf("C<\/",t10)+1; descrip2 = result.substring(t10,t11); CF.widget("babytemp").label=result.substring(t10,t11);
// Baby Hygro h10 = result.indexOf("Baby Hygro",start)+23; h11 = result.indexOf("H.<\/",h10)+2; hdescrip2 = result.substring(h10,h11); CF.widget("babyhygro").label=result.substring(h10,h11);
// Bios Temp t12 = result.indexOf("Bios Temp",start)+22; t13 = result.indexOf("C<\/",t12)+1; descrip2 = result.substring(t12,t13); CF.widget("biostemp").label=result.substring(t12,t13);
// Bios Hygro h12 = result.indexOf("Bios Hygro",start)+23; h13 = result.indexOf("H.<\/",h12)+2; hdescrip2 = result.substring(h12,h13); CF.widget("bioshygro").label=result.substring(h12,h13); // Badkamer Temp t14 = result.indexOf("Badkamer Temp",start)+26; t15 = result.indexOf("C<\/",t14)+1; descrip2 = result.substring(t14,t15); CF.widget("badkamertemp").label=result.substring(t14,t15);
// Badkamer Hygro h14 = result.indexOf("Badkamer Hygro",start)+27; h15 = result.indexOf("H.<\/",h14)+2; hdescrip2 = result.substring(h14,h15); CF.widget("badkamerhygro").label=result.substring(h14,h15);
// Woonkamer Baro B1 = result.indexOf("Woonkamer Baro",start)+27; B2 = result.indexOf("hPa",B1)+3; descrip2 = result.substring(B1,B2); CF.widget("woonkamerbaro").label=result.substring(B1,B2);
//System.print(event1); //System.print(descrip1);
};
socket.onClose = function() { //System.print("Gesloten"); };
socket.onIOError = function(e) { };
if(socket.connected == false) { socket.connect('192.168.1.100', 80, 3000); };
++++++++++++++++++
|
|
Post 2 made on Sunday December 23, 2007 at 12:23 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Being a Homeseer user, I have a plugin that works with the Pronto. If you are interested drop me a line. It handles many of the common homeser functions and has full IR out using a Global cache as the IR sender. Simple commandf rom the pronto causes any IR string/macro to be sent. Plug in handles the macros, not the Pronto
|
|
Post 3 made on Sunday December 23, 2007 at 12:33 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,007 |
|
|
If you look closely at the code, you can see things like this:
B1 = result.indexOf("Woonkamer Baro",start)+27; B2 = result.indexOf("hPa",B1)+3; descrip2 = result.substring(B1,B2); CF.widget("woonkamerbaro").label=result.substring(B1,B2);
Here, you are declaring a variable descrip2, building a substring and assigning it to the variable. On the next line, you do substring again. Not very performant.
This is better: CF.widget("woonkamerbaro").label=descrip2;
Consider replacing label assignment using this pattern as you have temporary variables you are creating. No need for 2nd .substring call.
You
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
OP | Post 4 made on Sunday December 23, 2007 at 13:47 |
Barry, you have PM I'm interested in your plugin. I have already installed need little help Thanks On December 23, 2007 at 12:23, Barry Gordon said...
Being a Homeseer user, I have a plugin that works with the Pronto. If you are interested drop me a line. It handles many of the common homeser functions and has full IR out using a Global cache as the IR sender. Simple commandf rom the pronto causes any IR string/macro to be sent. Plug in handles the macros, not the Pronto
|
|
OP | Post 5 made on Sunday December 23, 2007 at 13:54 |
@Lyndel Thanks for the help. can the line also build without the declaration of the descrip2 If i look at the code there is no need for that or not? Chak On December 23, 2007 at 12:33, Lyndel McGee said...
If you look closely at the code, you can see things like this:
B1 = result.indexOf("Woonkamer Baro",start)+27; B2 = result.indexOf("hPa",B1)+3; descrip2 = result.substring(B1,B2); CF.widget("woonkamerbaro").label=result.substring(B1,B2);
Here, you are declaring a variable descrip2, building a substring and assigning it to the variable. On the next line, you do substring again. Not very performant.
This is better: CF.widget("woonkamerbaro").label=descrip2;
Consider replacing label assignment using this pattern as you have temporary variables you are creating. No need for 2nd .substring call.
You
|
|
Post 6 made on Sunday December 23, 2007 at 16:45 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Chak, Where is PM? I can not even find a privaTe message area on this board. Checked Homeseer no there either. Send my an email to my first name @the-gordons.net
|
|
OP | Post 7 made on Sunday December 23, 2007 at 17:14 |
Barry, all the messages that I'm sending are returning back. Undelivered Mail Returned to Sender [email protected]: Host or domain name not found. Name service error for name=mail.the-gordons.net type=A: Host not found my e-mail name @fastmail.fm
|
|
Post 8 made on Sunday December 23, 2007 at 19:20 |
Daniel Tonks Wrangler of Remotes |
Joined: Posts: | October 1998 28,781 |
|
|
Barry: PMs are via the "RC Mail" link in the top grey bar, by "Forum Search".
If you don't see this, you have to log out of your account and back in again to activate it.
|
|
Post 9 made on Sunday December 23, 2007 at 21:36 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Chak, I assume you are using barry@.... My eMail is off the air till after the Holiday. Should be back up on Wednesday 12/26. Need to straighten out a mistake at my email service forwarder. They will not be happy.
Last edited by Barry Gordon
on December 24, 2007 00:20.
|
|
OP | Post 10 made on Monday December 24, 2007 at 03:48 |
Barry, thanks for the update, Your HS plugin is working great..:)
Happy holidays
Chak
|
|
Post 11 made on Monday December 24, 2007 at 10:51 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
My email is once again fixed with a lot of embarrassed people at TZO.com. They will probably blame it on a "computer glitch" which is a misnomer at best.
If you need any changes to the plugin or want additional HS functions added let me know. I do have a newer version in which I added some additional calls, but you may already have it. The latest one I have in production is version 2.0.366.
I'm curious, are you using the IR system (Global Cache) ?
|
|
Post 12 made on Monday December 24, 2007 at 14:44 |
Digit Long Time Member |
Joined: Posts: | December 2007 11 |
|
|
On December 23, 2007 at 07:58, Chak said...
++++++++++++++++++++++++ //var start = 0; //var result = ""; var socket = new TCPSocket(false);
socket.onConnect = function() { // System.print("OnConnect"); socket.write("GET /rover.asp?show=locWeer&options=10100010000000 HTTP/1.0\r\n"); socket.write("Accept: */*\r\n"); socket.write("Host: 192.168.1.100\r\n"); socket.write("\r\n"); }; Hmm, deja vu: [Link: domoticaforum.eu]All this is based on the weather demo ofcourse i found 2 months ago here at the remotecentral. I finally bought myself a TSU9600 as a christmas present last week :-) With a slightly modified script i'm also controlling my X10 devices, switching on/off webcams; just anything that's connected! Robert.
|
Robert Hekkers www.hekkers.netBuilding an automated and online home |
|
OP | Post 13 made on Monday December 24, 2007 at 15:36 |
He Robert, I have optimized the code a bit extra
Using the Plugin from Barry Gordon is the best solution. I will convert it soon.
// Woonkamer Temp T1 = result.indexOf("Woonkamer Temp",start)+27; T2 = result.indexOf("C<\/",T1)+1; CF.widget("woonkamertemp").label=result.substring(T1,T2);
// Woonkamer Hygro T1 = result.indexOf("Woonkamer Hygro",start)+28; T2 = result.indexOf("H.<\/",T1)+2; CF.widget("woonkamerhygro").label=result.substring(T1,T2);
|
|
Post 14 made on Wednesday December 26, 2007 at 18:57 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,007 |
|
|
On December 23, 2007 at 13:54, Chak said...
@Lyndel Thanks for the help. can the line also build without the declaration of the descrip2 If i look at the code there is no need for that or not?
Chak Chak, You are correct. You don't need the inline descrip2 variable assignment. You can simply assign the result of substring() to the label.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 15 made on Thursday December 27, 2007 at 09:02 |
snelvuur Long Time Member |
Joined: Posts: | November 2007 55 |
|
|
You dont really need the "start=result.index" too. This is only used if you want to match multiple strings which all start with the same identifier. Say you want to match "temperature" , but somewhere else you have a value for "temperature" too, then you can use start index to start -after- the first value as example. If i'am correct here..
|
|
|
Before you can reply to a message... |
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now. |
Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.
|
|