473,769 Members | 7,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

looking for a cleaner way to make this work

5 New Member
I have this working but not as clean as it should be. I'm new to Perl and This has been my first project to monitor my solar equipment.

Here is the data stream

Expand|Select|Wrap|Line Numbers
  1. {"result":{"overview":[{"meta":"GriPwr","value":"3689","name":"GriPwr","unit":"W"},{"meta":"GriEgyTdy",
  2. "value":"2.763333886","name":"GriEgyTdy","unit":"kWh"},{"meta":"GriEgyTot","value":"11235.17878036864",
  3. "name":"GriEgyTot","unit":"kWh"},{"meta":"OpStt","value":"","name":"OpStt","unit":""},{"meta":"Msg","value":"",
  4. "name":"Msg","unit":""}]},"version":"1.0","format":"JSON","proc":"GetPlantOverview","id":"1"}
  5.  
Here is my code.
It give it to me in a decent view. lookin to find out how much easier it would have been to make this work in a table format and how to get it to auto refresh.



Expand|Select|Wrap|Line Numbers
  1. #!c:/www/Perl/bin/perl
  2.  
  3. use strict;
  4.  
  5. use IO::Socket::INET;
  6.  
  7. my $webboxIP = "192.168.1.10";
  8.  
  9. my $request = '{ "version":"1.0", "proc":"GetPlantOverview", "id":"1", "format":"JSON" }';
  10.  
  11. $request =~ s/\s//go;
  12. $request =~ s/(.)/$1\0/go;
  13.  
  14. my $myRecvSocket = new IO::Socket::INET->new(LocalPort=>34268,Proto=>'udp');
  15. my $mySendSocket = new IO::Socket::INET->new(PeerPort=>34268,Proto=>'udp',PeerAddr=>"$webboxIP");
  16. my $sentCharacters = $mySendSocket->send($request);
  17. if (defined $sentCharacters) {
  18. # print "Sent $sentCharacters characters\n";
  19. } else {
  20. print "Error in send\n";
  21. }
  22. my $response;
  23. my $responder = $myRecvSocket->recv($response,1024);
  24. my @names;
  25. my @test1;
  26. my $string_to_find="value";
  27. #
  28. $response =~ s/\0//go;
  29. $response =~ s/\{//go;
  30. $response =~ s/\}//go;
  31. $response =~ s/\[//go;
  32. $response =~ s/\]//go;
  33. $response =~ s/"result":"overview":/<br>/go;
  34. $response =~ s/"meta":/<br>/go;
  35. $response =~ s/"OpStt","value":"","name":"OpStt","unit":""//go;
  36. $response =~ s/"Msg","value":"","name":"Msg","unit":""//go;
  37. $response =~ s/"version":"1.0","format":"JSON","proc":"GetPlantOverview","id":"1"//go;
  38. $response =~ s/,/<br>/go;
  39. #
  40. print "Content-type: text/html\n\n";
  41. print "<HTML><HEAD>\n";
  42. print "<TITLE>GetPlantOverview-test</TITLE>\n";
  43. print "</HEAD><body><h1>Live Solar Data via Webbox</h1>";
  44.  
  45. #
  46. print $response;
Mar 9 '08 #1
0 953

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1788
by: dusty | last post by:
Hi, I recently switched from windoze to Linux (SuSE 9.1) and want to write some applications (mostly for personal use). I have several years experience writing with Borland Delphi and now I am looking at Python. BlackAdder incorporates Python and QT into a application similar to Delphi for writing GUI applications. (I looked at Kylix and didn't like it) I wonder if BlackAdder is worth the price or would I be just as well off using Idle...
1
1850
by: Istvan Buki | last post by:
Dear C++ gurus, I'm having some problems inserting some template classes into containers. I'm looking for ideas, suggestions,... on how to achieve this but first let me explain my problem. Everything starts with a simple template class like the one below. In this example class A has two template parameters but that number can be different. template < typename T, typename U > class A
16
2041
by: Tommy Carlier | last post by:
I've created a data structuring format (you can't really call it a markup language), that behaves like XML, but that's much more flexible. You can have elements without names, attributes without names, you don't need something like CDATA or entities, and there's no such thing as DTD. Now I'm looking for an interesting name for it. I've thought of using a name like *ML (replace the * by any letter), but all the letters were already taken.
20
7356
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than Internet Explorer. Our computer expert in my company had told me already a while ago that I should learn HTML and encode myself. I was never inclined to do so (I am no computer expert), and when upon his suggestion I looked how my pages (converted to...
23
1585
by: walterbyrd | last post by:
Way back when, I got a lot of training and experience in highly structued software development. These days, I dabble with web-development, but I may become more serious. I consider php to be an abombination, the backward compatibility issues alone are reason enough to make me hate it. Rail looks promising, but it's difficult to find inexpensive hosting that supports rails. I like python much better, but I'm not certain it's as well...
16
2546
by: BLACKDOG157 | last post by:
I am starting to study dot net languages, and I'm wondering - which language do employers look for - C# or VB.net? Are they both equally powerful languages? Thanks, BD
13
3114
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
6
2149
by: Jack | last post by:
Basically I am trying to find a high performance web server. Since Python is installed on all of the servers, It'll be great if the web server is written in Python as well. Otherwise, I will have to install lighttpd or other web servers. Then the largest issue with Python-based web servers is performance. That's why I start to look into medusa or twisted-based servers. Twisted seems too big and complicated for what I really want to do...
0
1253
by: myprotein | last post by:
if "all applications disconnection" is anathor tigger of page cleaner? hi all I discovered that when all application disconnect from the database, db2 will "truncate" current active log file and push forward a new log file either by reusing a exist log or by generating a new log file. when anather application get connected to current database, execute "db2 get db cfg for xxxxx", u should see that the first active log is just the file...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.