-
GMU Flood Hazards Research Lab posted an update in the group Data Logger Developers 6 years, 6 months ago
Hello we are wondering if we could have some help with our code. Prior to going to the Mayfly development conference at Shenandoah University we were attempting to build our own data loggers. We were using Arduino Mega 2560’s, a ping sonar sensor, an RTC, and a Sim808 breakout board. We are able to generate time stamped data and we converted it into a simple string so we could collapse the data into the smallest piece of information available. The problem is when we send the data out using the Sim808 library the data being sent needs to be contained in quotes “datastring”. But when we put it in quotes it just sends out the text of the variable we are calling upon instead of sending out the data. Any help would be appreciated. We asked Shannon at the conference and she said to post the code on here to see if we could get some help.
Thanks,
DanCode:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PHONE_NUMBER “17855504756”
int year1;// this constant won’t change. It’s the pin number of the sensor’s output:
const int pingPin = 22;DFRobot_SIM808 sim808(&Serial);
void setup() {
// initialize serial communication:
Serial.begin(9600);
//******** Initialize sim808 module *************
while(sim808.init()) {
delay(1000);
Serial.print(“Sim808 init error\r\n”);
}
}void loop()
{
// establish variables for duration of the ping, and the distance result
// in inches and centimeters:
long duration, inches, cm;// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);// The same pin is used to read the signal from the PING))): a HIGH pulse
// whose duration is the time (in microseconds) from the sending of the ping
// to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.begin(9600);
while (!Serial) ; // wait until Arduino Serial Monitor opens
setSyncProvider(RTC.get); // the function to get the time from the RTC Serial.print(inches);
//Serial.print(“in, “);
//Serial.print(cm);
//Serial.print(“cm, “);
//Serial.print(” “);
//Serial.print(day());
//Serial.print(” “);
//Serial.print(month());
//Serial.print(” “);
//Serial.print(year());
//Serial.print(” “);
//Serial.print(hour());
//Serial.print(” “);
//Serial.print(minute());
//Serial.print(” “);
//Serial.print(second());
//Serial.println();
delay(1000);
String data0 = “print”;
String data1 = “print”;
String data2 = “print”;
String data3 = “print”;
String data4 = “print”;
String data5 = “print”;
String data6 = “print”;
String data7 = “print”;
String data8 = ” “;
data0 = String(month());
data1 = String(day());
year1 = year()-2000;
data2 = String(year1);
data3 = String(hour());
data4 = String(minute());
data5 = String(second());
data6 = String(inches);
char whocares;
data7 = String(data0 + data1 + data2 + data3 + data4 + data5 + data6 + data8);
delay(1000);
sim808.sendSMS(PHONE_NUMBER,data7);}
//String data7 = “print”;
//data7 = String(data0 + data1 + data2 + data3 + data4 + data5 + data6);
//const finaldata ”
//void loop2() {
//Serial.print(finaldata)long microsecondsToInches(long microseconds) {
// According to Parallax’s datasheet for the PING))), there are 73.746
// microseconds per inch (i.e. sound travels at 1130 feet per second).
// This gives the distance travelled by the ping, outbound and return,
// so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the object we
// take half of the distance travelled.
return microseconds / 29 / 2;
}
data7 = String(‘ ” ‘ + data0 + data1 + data2 + data3 + data4 + data5 + data6 + data8 + ‘ ” ‘);
for visual purposes I added a space between the single quotes and the double quote. you probably want to remove those extra spaces in the sketch
Can also do…..
String quotes = String(34);
data7 = String(quotes + data0 + data1 + data2 + data3 + data4 + data5 + data6 + data8 + quotes);