Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

Reply To: Double_logger example modification

Home Forums Mayfly Data Logger Double_logger example modification Reply To: Double_logger example modification

Sara Damiano

@w3asa – I don’t have formal training in computer science or even in electrical engineering.   I have one bachelor’s level degree – in chemistry.

– two things with your code – and I completely understand why you did it the way you did – because the example did.  Blame the chemist.

1 – you’re creating each variable 3 times instead of creating it once and then referring it to that same one later.  Each time you use that “new” keyword it creates a new variable, but you can only assign one variable of each type to a sensor so the other two weren’t getting updated.  In the double logging example it worked fine to create the variables with “new” right in the variable array because there was no overlap between the two arrays.  But that definitely wansn’t made clear and is confusing.  Anyway, to fix that change your variable arrays so that instead of creating a new variable they use the same variable that you already created up in the sensor sections like so:

Since you only use the free RAM in one of the two arrays and battery in the other and you didn’t create either at the top, it’s fine to create them “new” in the array. If you decide you do want them in both or the look of the code bothers you, you can create the free ram and battery variables with statements like Variable *yourVarName = new ProcessorStats_FreeRam(&mcuBoard, ...) up in the processor section or elsewhere above.

2 – Modems in ModularSensors are special; they don’t get updated like regular variables tied to a sensor.  The signal quality isn’t update until *after* you send out some data.  With each cycle, the signal strength saved to the csv and posted is actually the data from one cycle prior.  And if you never post data (you don’t) and explicitly update the modem metadata, the values don’t update.  You’d want to add publishing code like this in the “high” section right after turning off the SD card.