Author Topic: Backyard WeatherStation for Planting and later Aquaponics.  (Read 30616 times)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #15 on: January 03, 2014, 07:59:43 AM »
He's basically casting the Temp struct variable to a byte pointer. So the Temp struct variable is somewhere in memory and it's of type Temp (same name as variable .. a bit confusing but possible). The sendWithRetry function has no idea what Temp is and expects a very basic byte pointer (pointer to a bunch of bytes in memory) and the # of bytes to read from that location. So the casting syntax is just taking that Temp and casting it's address to a byte pointer so the function can look at it as an array of bytes. The last argument is just getting the size of the Temp variable so the function knows how many bytes to read after the initial location.

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #16 on: January 03, 2014, 08:05:06 AM »
if (radio.sendWithRetry(GATEWAYID, (const void*) (&Temps), sizeof(Temps)))

I don't understand "(const void*) (&Temps)?  Can you explain that one to me?  This is some way of pointing to the structure yes?  Do you have any links that led you to this? 


Truth be told:
  • That part isn't my code, it was copied directly from Felix's Struct_send example code.
  • I didn't really understand it either, but since you asked the question I looked it up.

From http://www.learncpp.com/cpp-tutorial/613-void-pointers/
Quote
The void pointer, also known as the generic pointer, is a special type of pointer that can be pointed at objects of any data type! A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type:
The sendWithRetry function's job is simply to send to another radio with a given ID number (arg1), data from a section of memory (arg2), some number of bytes (arg3). To avoid having to write a different send function for each type of data, Felix wrote it as taking a pointer to the data, and since it could be data of any type, it is a generic pointer.

From http://stackoverflow.com/questions/5547131/c-question-const-void-vs-void
Quote
As a general rule, if a function you write takes in a pointer to a value that you're not going to modify, then the function signature should use a const pointer. Using a pointer that isn't declared const means that the memory you're pointing to is allowed to be modified.

So, the way I understand it, if we were to send data to the function as a 'regular' variable, a copy would be sent to the function and we have no worry that it will modify the original data, But we would need to have different functions for different types, or cast the data from one type to another which is not really good programming practice. So we are instead sending a pointer to the location of the actual data. This means the function has the opportunity to modify the data (whether it does or not), which could lead to unexpected results. To keep this from being an issue, the function call is written with the const to tell both the programmer and the compiler that the data will not be modified by the function.

Please, any of you who actually speak C, confirm or clarify.

LG

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #17 on: January 03, 2014, 08:20:56 AM »
I think we both replied at the same time and mine went through first :P
But you're spot on, just another way of putting it, more documented I suppose, thanks :)
I love how C really forces one to understand memory allocation and pointers, the bare metal of computer programming.
That's why C is the border between copy and paste programmer land, and true computer science land, no offense intended ;)
« Last Edit: January 03, 2014, 08:23:11 AM by Felix »

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #18 on: January 03, 2014, 08:36:32 AM »
I think we both replied at the same time and mine went through first :P
But you're spot on, just another way of putting it, more documented I suppose, thanks :)
I love how C really forces one to understand memory allocation and pointers, the bare metal of computer programming.
That's why C is the border between copy and paste programmer land, and true computer science land, no offense intended ;)

Yeah, I got the "another reply was posted" warning, but I had spent 20 minutes figgering it out for myself and writing it up well enough so that I thought I understood it and I'll be durned if I aint gonna post it!

No offense taken. I was always better at hardware than software through college. I wish now that I had forced the issue and REALLY learned C.

LG

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #19 on: January 03, 2014, 10:21:21 PM »
Thank you both, LG and Felix,

     I've got it now. I'm starting to remember things now.  I remember at the time I was writing C code and this wasn't a very long time at all that Void pointers were taboo.  I was working on a Sparc workstation in a Unix environment.   I remember we had just got 16 colors!  It was amazing at the time.  You could do it but you had to force the compiler to let you do it.  I've got to forget some of the rules from the past. 
    Going on Felix's idea of getting closer to the computer.  I think that is why I've written in Assembly since then.  You know exactly what is going on.  You are in control of all timing.  The higher the level of language the harder it is to keep track of such things.  I am enjoying this though.  It takes much less time to code.  I feel as LG too.  I wish I hadn't walked away from C.  I'm amazed how far it has come with micros.  The wealth of libraries, and available functions for Ardiuino is really nice.
     I'm looking forward to being able to help you guys out.  Perhaps one day. 
     

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #20 on: January 04, 2014, 12:29:44 AM »
     Got it up and running.  I'm glad to have changed to the packet format.  I'm seeing what looks like an obvious pattern here.  I'm getting an invalid packet after pinging the Node from the Gateway.  I don't receive a reply to the ping....but...I get an invalid packet.  Perhaps I am getting the reply but I'm interpreting it wrong?
     Now I've just got to box this thing up and put it in place.  Oh forgot to finish the Raspi part of it. :o 



TerminalDataNoPingReturn by hexibot43, on Flickr

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #21 on: January 04, 2014, 09:49:16 AM »
Thanks for attaching a link and not embedding the pictures .. helps with keeping my backups smaller even though they keep growing and growing and taking longer to generate and copy.

I've done a fair share of assembly in university courses and I have to say it's not the answer to my prayers in terms of productivity. It's great and probably required to understand computer architecture but I'll prefer compilers and assemblers to do the hard work.

On your ACK issue ..
I think you're getting back an empty message with the ACK flag set. Not sure if you posted code (sorry about being too lazy to check) but unless you send the ACK message with an actual payload, you will get just that ... an empty message (length 0) but with the ACK header flag=1, enabling to you check whether an ACK was received. So instead of trying to match your real expected payload to the ACK, just check whether it's an ACK. Look at the struct send/receive examples where I send with ACK:

https://github.com/LowPowerLab/RFM69/blob/master/Examples/Struct_send/Struct_send.ino
https://github.com/LowPowerLab/RFM69/blob/master/Examples/Struct_receive/Struct_receive.ino

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #22 on: January 14, 2014, 01:08:56 AM »


Quote
I think abstracting the sensor reporting a bit would be worth the bit overhead. I'm not sure if we'd need to go to the point of using the Adafruit Unified Sensor Driver framework but it might not hurt. A data string would consist of:

     The idea of a Unified sensor driver is really growing on me. 

     Things are really starting to work now that I've actually got the radios working.  And working really well.  I can't believe how well these Moteinos are working.  I can communicate from one corner of my property to the other without a hitch.  Somehow I had it in my head that I'd bought them with just RFM69w radios instead of the RFM69hw which I have.  I'm getting old.

     I spent this last Saturday setting up a web server on a Raspberry Pi.  Took me two tries to get it up and running with Apache2+php+mysql.  Actually got a couple webpages up and running locally.  For some weird reason my ATT router doesn't seem to want to allow me to provide a port forwarding to it.  It won't list the Raspberry PI as an available device for port forwarding ?!?!  I've got it hooked up via wifi to an access point on my network.  I'm guessing I'm going to have to wire it.  Well once I get it connected to the NET I'll post a link.

     Now I've just got to figure out the part in between.  Can Node.js, and socket.io be easily installed into Apache2 with PHP and Mysql? 

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #23 on: January 14, 2014, 09:44:04 AM »
Now I've just got to figure out the part in between.  Can Node.js, and socket.io be easily installed into Apache2 with PHP and Mysql?
Node.js is standalone and doesn't depend on the LAMP stack. But they can work together of course. Socket.io piggy backs on node.js (think module). I stopped using Apache and moved to Nginx since it's much lighter on the Pi. But Apache works too..

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #24 on: January 14, 2014, 11:34:28 AM »
Quote
I stopped using Apache and moved to Nginx since it's much lighter on the Pi. But Apache works too..

Yes, I think I'm going to try your approach.  It will make things easier to ask questions if I have problems.  I attempted to add socket.io and node.js to the server I had already installed.  I was able to verify installation of all of it, but when I went to go run the the Chat.html code it looked like it couldn't interpret the first part of the code and so just pumped it as text to the web server.  I will try and get a screen dump of it when I get home.  Perhaps someone has some insight.  But I will be buying another SD card on my way home to give Nginx a try.  Thanks Felix for everything.  This is a fun journey.

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #25 on: January 16, 2014, 02:39:26 AM »
Quote
// During this time power consumption is minimized
   radio.sleep();  // Put radio to sleep      This worked
Narcoleptic.delay(60000); // this should be 1 minute?   This didn't
   radio.wake();  // Turn Radio back on  This didn't work.

     The radio sleep function was accepted by the compiler.  But I couldn't seem to get the wake function to be accepted.  Is there a wake function in the RFM69 libraries?  And for some reason my call to the Narcoleptic library was a bust too.  There was no delay.  I put a delay call in its place and that works just fine as a time delay.  But no sleep for the Moteino.  Is this library compatible with the Moteino?  The Naro delay only lasts about 9 millis.  Watching the serial out confers this.  If I put a simple delay(60000); in it's place I get the full 1 minute delay.  I know the Millis() function timer is suppose to be stalled when you call Naroleptic.delay but it doesn't seem to be doing that either.

Quote
https://code.google.com/p/narcoleptic/issues/detail?id=3
 

Has anybody else tried this library?

   
« Last Edit: January 16, 2014, 02:57:46 AM by hexibot43 »

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #26 on: January 16, 2014, 09:05:46 AM »
[Yoda voice]Felix say, wake, there is not, send, there is.[/Yoda voice]

...
I was wrong about wake. There is no wakeup in RFM69, only a sleep() function. When you want to wake the radio, you don't have to do anything, just use send() or sendWithRetry() directly and the radio will wake up. ...

I had some wonkyness using the LowPower.powerDown() function as well, it did not seem to be sleeping the way I expected, I did not debug this. I have not tried the Narcoleptic library.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #27 on: January 16, 2014, 10:00:42 AM »
I have used narcoleptic and it works fine.
There is no radio.wake() function for RFM69. The radio will wake whenever you will try to do anything else other than sleep with it.

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #28 on: January 16, 2014, 10:12:01 AM »
Thanks LG

I had feeling that was what you were going to say about the radio library.  Half my problem solved.  I get the power usage down and I'm ready to deploy my first Moteino to the backyard for good! 

Did you ever find a good way to sleep the Moteino?  I was going to try the LowPower library next to see what happens.  Now I'm wondering if that is the right move.....

Alright Felix - I will look for something else wrong with my copy of the Narcoleptic library and try again.  Thanks

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Backyard WeatherStation for Planting and later Aquaponics.
« Reply #29 on: January 17, 2014, 10:05:02 AM »
     Wasn't having good luck with the Narcoleptic Library.  For some reason I wouldn't get the delay.  My code ran like the call to the library wasn't even there.  8 millis time to run the call to the library.  Not sure what was going on there.  Switched to

https://github.com/n0m1/Sleep_n0m1

And now I've got what looks like a shutdown, and an actual sleep time of 1 minute for the time being.  Looks like even the Millis counter is being shut down.  By the count about 100 millis tick off in the course of a minute. 

Not sure what my problem with the Narcoleptic library.  If anyone has any insight I'm all ears. 

Time to remove all the serial debugging code, box it up, and put it in place.

Code for my Node as it is now.

http://codebender.cc/sketch:26389

Learning a lot here.  The next nodes should be a lot easier now.  Thanks everyone for all the help.  I'm really impressed with the Moteino.  It is exactly what I need, and no more.