Home  5  Books  5  GBEzine  5  News  5  HelpDesk  5  Register  5  GreenBuilding.co.uk
Not signed in (Sign In)

Categories



Green Building Bible, Fourth Edition
Green Building Bible, fourth edition (both books)
These two books are the perfect starting place to help you get to grips with one of the most vitally important aspects of our society - our homes and living environment.

Buy individually or both books together. Delivery is free!


widget @ surfing-waves.com




Vanilla 1.0.3 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome to new Forum Visitors
Join the forum now and benefit from discussions with thousands of other green building fans and discounts on Green Building Press publications: Apply now.




    •  
      CommentAuthorSteamyTea
    • CommentTimeJan 19th 2015
     
    Caius
    Thanks.
    I think it was me that asked about one or many scripts to do things.
    Going to start working on it in earnest today, I have a pencil with a rubber at the other end, let's see which end wears out quickest.
    • CommentAuthorsnyggapa
    • CommentTimeJan 19th 2015
     
    I use a cloud service to collect my energy readings and do the charting / analysis - gets data via an HTTP post and works very well for what i want to do - I use an arduino for the posting but the rPI should work equally well

    an example of what I get out (you can also get the raw data) is here

    https://grovestreams.com/singleDash.html?org=b1343ea7-bff5-303b-9d31-89469cd583ab&itemUid=7e8f1935-2742-3d22-87fe-0f4f1fa9c8ba&api_key=2c615462-fe55-38c3-b8b9-cb31f141bc84&title=FlottageBoard&titleColor=000000

    grovestreams just gets raw data, it then derives the rest like daily usages, day/night split etc from the raw data. And it's free for less than 10,000 transactions/month and very little money for above that. I post a set of data every 5 minutes which comes to less that 10,000 per month, so free to me :)

    -Steve
    • CommentAuthorEd Davies
    • CommentTimeJan 19th 2015 edited
     
    Posted By: borpinBetter if the clients simply send the data regularly or by exception to a 'static' server.
    There have been a couple of comments on this theme. I'd agree in general but practically it might turn out in this case easier to open a port on the sensor machine's net than the central site's, particularly for Steamy's initial demo (because the sensor is on his home network whereas the central machine is in an office with separate IT people) . All a matter of circumstances. The key is not to have the overall design too dependent on the communications details.
    • CommentAuthorcjard
    • CommentTimeJan 20th 2015
     
    <blockquote><cite>Posted By: Ed Davies</cite>the central machine is in an office with separate IT people</blockquote>

    Nothing like making a job easy from the start eh?

    "Hmm.. I need to get into something regularly. I know. I'll use one of the cells at the prison where I work"



    When amazon and azure will give free micro virtual machines away with totally configurable security, choosing to site a server at a network where the security is under the control of people who have bigger problems and deeper concerns is perhaps not ideal
    •  
      CommentAuthorSteamyTea
    • CommentTimeJan 20th 2015 edited
     
    I have done a bit, almost working on my home network.
    I need to check if I can reach the RPi that is doing the logging at home from the big scary world (I know a cafe with a good view and free wireless). Hopefully I have set up my port forwarding right, guess I will find out if I wake up to no files and plenty of Trojans. Shall pull the lead on the NAS!
    I can grab data of the logging RPi from a remote RPi using ssh in a Python script. I have set up passwordless login with RSA, so hopefully I am secure. All passwords have been changed to 'quite tricky ones'. So tricky I keep getting them wrong.

    So my Python script on the Office RPi can send a request for data to my Logging RPi and that gets sent back. It prints out to the screen no problem.
    Unfortunate when I try and save that data as a .csv file I just get a stream of zeros. There was some message about not being an int value (integer). Need to look at that. Not sure if it is the way the data is transported, or read 'back at the Office'. Just surprised I have got this far without serious upset (writing things down does help).

    I lost a day re-writing my CC reading script, was pretty easy once I had finished (dumb mistake not defining it). But now it just logs what I want rather than everything spewing out the CC.
    Out of interest, and to save me having a go on something working, can I use 'or' in an if statement. Something like:

    If == 100 or 200 or 300

    Where would I put the :
    After every condition or just at the end?

    Off to bed now, not a real programmer, can't live off Red Bull and Pizza.

    Thanks for all your help and suggestion.
    • CommentAuthorcjard
    • CommentTimeJan 21st 2015
     
    It the data looks right when you print it to the console then it won't be a transport issue. Consider looking for a library that makes csv files, there are some wheels not worth reinventing

    I'm no python expert but typically programming languages don't work like that. It's a very human thing to remember the left hand operand ( i ) and then look at everything to the right of the operator as the other operand. The computer just sees it as a bunch of operators ( = + * > or and so on) and on either side the two operators. As a result the computer sees if i == 1 or 2 or 3 as

    If ( i == 1 ) or ( 2 or 3)

    Whether it can resolve (2or3) to true depends on the language. In some it fails. In some it may become either a 2 or a 0, which may then be true or false depending on how it sees numbers and booleans. In some it may work, though the coding community would generally avoid those languages

    Your options for doing thus are varied. I'd choose the simplest:

    If k == 1 or k==2 or k==3 :

    The colon goes at the end of the line
    • CommentAuthorEd Davies
    • CommentTimeJan 21st 2015
     
    What cjard says but perhaps the colloquial Python way to do that would be:

    if i in (100, 200, 300):

    or

    if i in {100, 200, 300}:

    I.e., using membership testing on a tuple or set. Could use a list, [100, 200, 300], or a dictionary as well if wanted.
    •  
      CommentAuthorSteamyTea
    • CommentTimeJan 21st 2015 edited
     
    Thanks

    The good news is that I can log in remotely using Firessh from a cafe overlooking the sea. So that bit seems to be OK.
    Just got to sort this strange thing with the zeros when I try and save the data to a file.

    I have a line something like

    fandata = (ssh pi@192.168.1.100 cat "/home/pi/CurrentCost/oneline.csv")

    This prints to the screen fine and updates every few seconds, but when I try and append it to a file with

    tfile = open("/home/pi/RemoteData/oneline.csv", "a")
    tfile.write("%s"%fandata + "\n")
    tfile.close()

    I just get this error message about int not being defined.

    I may have made an error in the fandata = line as I am doing that from memory.

    Edit

    Changed the code above as it was total nonsense.
    But thinking about it, as I am using cat, I should be able to just write to an existing file as it concatenates. Is that right?
    • CommentAuthorEd Davies
    • CommentTimeJan 22nd 2015 edited
     
    Posted By: SteamyTeaChanged the code above as it was total nonsense.
    Good, it was. :smile: You need to use subprocess.Popen or something to execute a command, you can't just write it in a string.

    In general something like "%s" % fandata is pretty meaningless; you might as well just write fandata I'm not quite sure what you had in mind but perhaps it could be done a little more compactly with "%s\n" % fandata
    But thinking about it, as I am using cat, I should be able to just write to an existing file as it concatenates. Is that right?
    cat concatenates its input files to produce a single output file. (About the only time I use it like that is to concatenate public keys from multiple ssh clients to form the authorized_keys file in the .ssh directory on the host, as I described in email.) To concatenate the output of cat onto an existing file you need to use something else. If it's all on one machine:

    cat input1 input2 >> outputadds the contents of the two input files in turn to the output file. Doing redirection like this over ssh or within a Python subprocess.Popen call is more tricky as redirections are handled by the shell (often bash or dash). What I think you want might be done in a shell script on the central data-collection machine using:

    ssh pi@192.168.1.100 cat "/home/pi/CurrentCost/oneline.csv" >> /home/pi/RemoteData/oneline.csvYou could get a similar effect in a Python script fairly easily but it would be a few lines of code.

    If you were running a script on the sensor machine (the one with the CurrentCost connected) then something like:

    cat "/home/pi/CurrentCost/oneline.csv" | ssh steamy@server.charity.org tee --append /home/pi/RemoteData/oneline.csvmight append on the server appropriately - with a few tweaks to the file names.
    •  
      CommentAuthorSteamyTea
    • CommentTimeJan 22nd 2015
     
    I have managed to get something working on my home network. Not very pretty but it is doing what it should, so can use that as the proof of concept.
    If the tender is won, then I can try it out in the real world and worry about putting all the little things right, things like my router IP address changing.

    Working for the next few days so it will all come to a stop now till next week. Quite chuffed that the concept is sound.

    Thanks for your help.
  1.  
    •  
      CommentAuthorSteamyTea
    • CommentTimeFeb 2nd 2015
     
    Rather they put an RTC in it, not going to make any difference to me having more cores.
    • CommentAuthorcjard
    • CommentTimeFeb 2nd 2015 edited
     
    •  
      CommentAuthorSteamyTea
    • CommentTimeFeb 2nd 2015
     
    I have some, but they make using the GPIO pins tricky, including the 5V one. Well the ones I have. Then things don't fit in the cases too well.
    I would rather and RTC was there than an ADC, though both would be best.
Add your comments

    Username Password
  • Format comments as
 
   
The Ecobuilding Buzz
Site Map    |   Home    |   View Cart    |   Pressroom   |   Business   |   Links   
Logout    

© Green Building Press