Hello!
I'm somewhat quite desperate with this project. The deadline is pretty much now so sorry if I'm hasty or unpolite. :,D
So, I want to send multiple strings, integers and floats from an Arduino Uno Master to a nodemcu slave.
The main idea of the project is that the Arduino is going to take input of multiple temperature sensors to control the temperature of an animal physiology experiment. The nodemcdu (ESP8266mod) is going to receive this temperature data from Arduino, log then into google drive and, if some parameters is wrong, send a e-mail to me.
I believe I got almost everything figured out. I know the wiring, how to log the data, how to send an email, how to send convert float to char and back to float, etc.
I have seen multiple tutorials and such (all of them coping from the same example...) and all of then deal with a simpler problem that deals with passing only one or two values with different byte sizes.(Tutorial example)
I need an example code that sends multiple variables. All of them will be less than 8byte in size.
The pseudocode of what I want to do is something as follows:
->>Arduino Master Writer
If one minute has passed {
Receive input from 8 sensors
Makes decisions based on said input
Then
Wire.beginTransmission(<adress>);
Wire.write(<date>); // String (ex. Set22)
Wire.write(<hour>); //String (ex. 14h33)
Wire.write(<Val sensor 1>); // float (I have read that it is easier if I convert it to string. Most likelly will do so)
Wire.write(<Val sensor n>); // float (ex. 23.444)
Wire.write(<Val sensor 8>); // float (ex. 30.222)
Wire.write(<state of equipment 1>); //bolean (wheter the equipment is on or off)
Wire.write(<state of equipment n>); //bolean (wheter the equipment is on or off)
Wire.write(<state of equipment 4>); //bolean (wheter the equipment is on or off)
Wire.write(<Val light sensor >); //int (ex. 50000)
Wire.endTransmission(); // stop transmitting
}
->>Nodemcu SlaveReceiver
void setup() {
Wire.begin(<adress>); //
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
}
void receiveEvent(int howMany) {
char a = Wire.read(<date>);
char b = Wire.read(<hour>);
float c = Wire.read(<Val sensor 1>);
etc
int n = Wire.read(<Val light sensor >);
upload2Drive(a,b...,n){}
shitHappened(a,b...n){} //sends email.
}
Can anybody please provide any example of something like that?
I've tried multiple search strings on google and could find nothing!
-Edit-
The main question here, I believe, is how to maintain the identity of each variable among the two boards. The tutorials counts bytes, (e.g., the last byte is another variable), but I needed something that would identify positions (e.g. the first value(<=8bytes) is the first variable, the second (<=8bytes) is the second etc...
Rola