Notifications
Clear all

Under new management??

108 Posts
5 Users
9 Likes
24.7 K Views
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Yes, that was what I was proposing, more or less!

so you never work with the bme280data directly under this scenario... 

So how do I write the struct that I am getting from my remotes, which don't have MIN or MAX members to the BaseStation object, would I need to create dummy values(0.0f) on the remote side?


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

So how do I write the struct that I am getting from my remotes, which don't have MIN or MAX members to the BaseStation object, would I need to create dummy values(0.0f) on the remote side?

1) You can send the bme280data from the remote sensor as normal.  Doing it this way will require a method in BaseStation to populate the bme280data object on the recieving end, OR...

// As this method is a part of WeatherStation class, it has direct access
// to update the bme280data object, for example:
void update(const bme280data& remote_sensor) {
  station = remote_sensor.station;
  temperature = remote_sensor.temperature;
  // Etc...   
 }

Make sense?

2) Add/create the whole bme280data and WeatherStation model on the remote sensor end, and just send the whole thing (the BaseStation object), because it is only one object anyway, made up of the two - What I demonstrated is only 25 bytes - member functions to not normally contribute to the size of the object.

This way would be:

network.write(header, &BaseStation , sizeof(BaseStation ));


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Let me explain the whole plan.

The two remote sensors are transmitting Station, Temperature, Humidity, Air Pressure and UV to the local base station approximately once per minute

The base station calculates the maximum and minimum daily values. The base station stores all 7 values in the EEPROM.

Every 20 seconds the EEPROM is read and the values from one sensor are displayed on the LCD, 20 seconds later the other sensor values are displayed.

I don't intend to update the LCD every time data is received!


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

Let me explain the whole plan.

OK, I think I'm clear on the plan 🙂
See my amendment to my last post, you may have missed it, as the timestamp doesn't seem to get updated on an edit.

You can do anything you want with the object once you get it to the base station.  I think method (1) is probably a good way to start, just amend the update member function to suit as shown.

Questions?

[edit] - I may have another idea... need to think about it for a bit, but still ok to send the bme as noted...


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

I forgot about the timestamp, but that would also be added to the object at the base station, retrieved from a DS3231 RTC.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

I forgot about the timestamp, but that would also be added to the object at the base station, retrieved from a DS3231 RTC.

No no, I mean the timestamp of my reply edits here on this forum 🙂

So does the function make sense?


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

So does the function make sense?

I'll let you know tomorrow, I am going to have to paste all these snippets into a text editor, as they are scattered over a couple of forum pages.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

No problem... it does get a bit hard to track things.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Would this make sense?

struct allData{
struct remoteData{
byte station;
float temperature;
float pressure;
float humidity;
float ultraviolet;
}remote;

float atticTempMax;
float atticTempMin;
float balconyTempMax;
float balconyTempMin;
}limitData;

limitData.remote.station = 10;
limitData.atticTempMax = 20.00;

   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

I have got this far:

#include <EEPROM.h>

struct localData{
  float TempMax;
  float TempMin;
  };

struct remoteData{
  byte station;
  float temperature;
  float pressure;
  float humidity;
  float ultraviolet;
  struct localData limits;
  };

remoteData atticData;

int startAddress = 0;

void setup() {

}

void loop() {

  atticData.station = 10;
  atticData.limits.atticTempMax = 13.55;
  
  // after filling out the rest of the struct

  EEPROM.put(startAddress, atticData);

}

I think this should work?

So correct me if I am wrong!

  1. Structs are just an ordered collection of primary data types!
  2. Classes are like structs but can also have their own methods!
  3. Namespaces are merely another abstract method of collecting objects together for naming purposes!

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

I think this should work?

It can work, but it's not really in the spirit of how OOP should work.  I have to run shortly, but I'll try to put together a bit of an explanation of what I mean, and give you an example of how it works tomorrow.

Posted by: @pugwash

So correct me if I am wrong!

  1. Structs are just an ordered collection of primary data types!
  2. Classes are like structs but can also have their own methods!
  3. Namespaces are merely another abstract method of collecting objects together for naming purposes!

In C, yes, structs are known as POD(Plain Old Data) types.
In C++, a struct is exactly the same as a class, except for their default behavior.
I wouldn't call namespaces abstract, as in an abstract class, which is quite different.  Namespaces introduce a new scope to avoid name clashes:

struct A {
  // structs have public access by default
  int X;
  };
A a;
a.X; // OK, accessible

class B {
  // classes have private access by default
  int X;
};
B b;
b.X; // Error, not accessible without a public access specifier

// Namespaces...
int X; // Global
namespace pugwash {
  int X; // New scope
}

Serial.print(X); // Access global
Serial.print(pugwash::X); // Your library version

Basically allows you to have same name functions, symbols in your library, otherwise there would be name clashes everywhere because everyone wants (for example) a print statement with the same name, etc...

This is why in the C++ ISO Standard, the whole of the C++ Standard Library is contained within a namespace called "std", for example: std::cout << foo << std::endl;

I'll try and come up with an abstract class example too, just as an FYI.

Cheers!


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Almost done and dusted!

Now I have the LCD connected and powered by 5V powerpack!

The single blue LED flash indicates that a transmission has been received.

And here is the code that is running it (tested for 24 hours):


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@pugwash

Great work!  Really interesting to see!!  ? 

SteveG


   
ReplyQuote
Page 4 / 8