Forum Replies Created
-
AuthorPosts
-
I thought about that too. I’m not sure if there is a way to check. The model number says it is supposed to be a 10 meter sensor. And the reading shows 9999 when the object is out of range. This is typical of the 10 meter models. I believe the 5 meter models show 4999 when out of range. Maxbotix isn’t sure what the problem is. They sent me an RMA to send it in and have it evaluated. Hopefully doing so finds the issue.
Thank you Heather.
FYI, the link to the data portal is not working. Or at least it isn’t working for me.
Sara
Thanks for the information on the data portal. I would like to use it for the simplicity, but I’m sure my clients would not like to have their data publicly available.
I have the database set up and the php script working to add the data to the database. Now I just need to get the sensor data sent to the database. I was confused on how Shannon’s code worked. After her explanation I think I have an idea. Basically my sensor code needs to be changed to create a string with the website address and the sensor data, and time stamp. I have spent several days reading examples trying to figure out how to generate the script. Finally last night I found one that I believe does what I need it to. Now I just have to sit down and figure out what parts of the existing code I don’t need and remove it. This is all way above my pay grade, so anything I come up with will not look right and probably won’t be the most efficient way to tie everything together. Add that to my lack of knowledge and that always makes if fun to try and figure out where the problems are.
Thanks for the help.
Scott
I’m 99% sure most if not all of this code is yours or someone associated with Envirodiy. If you can’t tell, I know very very very little about arduinos. I have a friend that put this together for me and I pointed him to this website for guidance. I’m sure he used the copy and paste method for coding. He didn’t have time to work with the xbee radios, so I took the code and changed things to serial1 to try and get the communication to work. It works, but obviously it isn’t the way things should be done. I have the V0.3 boards. I got them when you first went live with them. They are great boards and fun to play with.
The plan is to take the sonar reading, battery voltage, and date string send it to the base unit then have the base unit send it to the website and MySQL database. I would also like to save the string to an SD card at the base station. This way I have a backup if the network should go down.
You mentioned having a table for each sensor in the database. I could have up to 15 sensor loggers communicating to the base station in 1 to 5 minute intervals for one client. Is it possible to combine the strings from all sensor loggers into one and send it to one table in the database? The sensors will be setup on individual ponds, then the report would look like:
Pond 1, Pond 2, Pond 3, etc.These could probably be inserted into separate tables in the database then generate a report to combine them by date read.
This is getting way over my head. I appreciate all the help and code examples you are willing to share.
Scott
Ok, so it is the code on my sensor/logger that needs to be changed. Do you by chance have any example code that I can look at to try and figure out where I need to go? The sensor is an ultrasonic sensor. I have attached the code I am using for the sensor. This code will change as I only want to send data one time per day.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322[code]#include <Wire.h>#include <avr/sleep.h>#include <avr/wdt.h>#include <SPI.h>#include <SD.h>#include <RTCTimer.h>#include <Sodaq_DS3231.h>#include <Sodaq_PcInt_PCINT0.h>#include <SoftwareSerial_PCINT12.h>const int SonarExcite = 10;SoftwareSerial sonarSerial(11, -1);boolean stringComplete = false;#define READ_DELAY 1//RTC TimerRTCTimer timer;String dataRec = "";int currentminute;long currentepochtime = 0;float boardtemp = 0.0;int batteryPin = A6; // select the input pin for the potentiometerint batterysenseValue = 0; // variable to store the value coming from the sensorfloat batteryvoltage;int range_mm;//RTC Interrupt pin#define RTC_PIN A7#define RTC_INT_PERIOD EveryMinute#define SD_SS_PIN 12//The data log file#define FILE_NAME "SonicLog.txt"//Data header#define LOGGERNAME "Ultrasonic Maxbotix Sensor Datalogger"#define DATA_HEADER "DateTime,Loggertime,BoardTemp,Battery_V,SonarRange_mm"void setup(){//Initialise the serial connectionSerial1.begin(9600);sonarSerial.begin(9600);rtc.begin();delay(100);pinMode(8, OUTPUT);pinMode(9, OUTPUT);pinMode(SonarExcite, OUTPUT);digitalWrite(SonarExcite, LOW); //pin 10 is the power pin for the ultrasonic sensorgreenred4flash(); //blink the LEDs to show the board is onsetupLogFile();//Setup timer eventssetupTimer();//Setup sleep modesetupSleep();Serial1.println("Power On, running: ultrasonic_logger_example_1.ino");}void loop(){//Update the timertimer.update();if(currentminute % 2 == 0) //if the time ends in an even number, a sample will be taken. Can be changed to other intervals{digitalWrite(8, HIGH);dataRec = createDataRecord();delay(500);digitalWrite(SonarExcite, HIGH);delay(1000);range_mm = SonarRead();digitalWrite(SonarExcite, LOW);stringComplete = false;//Save the data record to the log filelogData(dataRec);//Echo the data to the serial connectionSerial1.println();Serial1.print("Data Record: ");Serial1.println(dataRec);String dataRec = "";digitalWrite(8, LOW);delay(500);}systemSleep();}void showTime(uint32_t ts){//Retrieve and display the current date/timeString dateTime = getDateTime();//Serial.println(dateTime);}void setupTimer(){//Schedule the wakeup every minutetimer.every(READ_DELAY, showTime);//Instruct the RTCTimer how to get the current time readingtimer.setNowCallback(getNow);}void wakeISR(){//Leave this blank}void setupSleep(){pinMode(RTC_PIN, INPUT_PULLUP);PcInt::attachInterrupt(RTC_PIN, wakeISR);//Setup the RTC in interrupt modertc.enableInterrupts(RTC_INT_PERIOD);//Set the sleep modeset_sleep_mode(SLEEP_MODE_PWR_DOWN);}void systemSleep(){//Wait until the serial ports have finished transmittingSerial1.flush();Serial1.flush();//The next timed interrupt will not be sent until this is clearedrtc.clearINTStatus();//Disable ADCADCSRA &= ~_BV(ADEN);//Sleep timenoInterrupts();sleep_enable();interrupts();sleep_cpu();sleep_disable();//Enbale ADCADCSRA |= _BV(ADEN);}String getDateTime(){String dateTimeStr;//Create a DateTime object from the current timeDateTime dt(rtc.makeDateTime(rtc.now().getEpoch()));currentepochtime = (dt.get()); //Unix time in secondscurrentminute = (dt.minute());//Convert it to a Stringdt.addToString(dateTimeStr);return dateTimeStr;}uint32_t getNow(){currentepochtime = rtc.now().getEpoch();return currentepochtime;}void greenred4flash(){for (int i=1; i <= 4; i++){digitalWrite(8, HIGH);digitalWrite(9, LOW);delay(50);digitalWrite(8, LOW);digitalWrite(9, HIGH);delay(50);}digitalWrite(9, LOW);}void setupLogFile(){//Initialise the SD cardif (!SD.begin(SD_SS_PIN)){Serial1.println("Error: SD card failed to initialise or is missing.");//Hang// while (true);}//Check if the file already existsbool oldFile = SD.exists(FILE_NAME);//Open the file in write modeFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Add header information if the file did not already existif (!oldFile){logFile.println(LOGGERNAME);logFile.println(DATA_HEADER);}//Close the file to save itlogFile.close();}void logData(String rec){//Re-open the fileFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Write the CSV datalogFile.println(rec);//Close the file to save itlogFile.close();}String createDataRecord(){//Create a String type data record in csv format//TimeDate, Loggertime,Temp_DS, Diff1, Diff2, boardtempString data = getDateTime();data += ",";rtc.convertTemperature(); //convert current temperature into registersboardtemp = rtc.getTemperature(); //Read temperature sensor valuebatterysenseValue = analogRead(batteryPin);batteryvoltage = (3.3/1023.) * 1.47 * batterysenseValue;data += currentepochtime;data += ",";addFloatToString(data, boardtemp, 3, 1); //floatdata += ",";addFloatToString(data, batteryvoltage, 4, 2);return data;}static void addFloatToString(String & str, float val, char width, unsigned char precision){char buffer[10];dtostrf(val, width, precision, buffer);str += buffer;}int SonarRead(){int result;char inData[5]; //char array to read data intoint index = 0;while (sonarSerial.read() != -1) {}while (stringComplete == false) {if (sonarSerial.available()){char rByte = sonarSerial.read(); //read serial input for "R" to mark start of dataif(rByte == 'R'){//Serial.println("rByte set");while (index < 4) //read next three character for range from sensor{if (sonarSerial.available()){inData[index] = sonarSerial.read();//Serial.println(inData[index]); //Debug lineindex++; // Increment where to write next}}inData[index] = 0x00; //add a padding byte at end for atoi() function}rByte = 0; //reset the rByte ready for next readingindex = 0; // Reset index ready for next readingstringComplete = true; // Set completion of read to trueresult = atoi(inData); // Changes string data into an integer for use}}dataRec += ",";dataRec += result;return result;}[/code]Ok, I can post data to the database via the URL, so the problem is somewhere in the Arduino code. I’m using your code above at my base. I changed all the required parameters to my network settings. It appears the Arduino Ethernet is communicating with the website as the php script is inserting the id and timestamp in the database table. I’m a little confused with the Arduino code. The php script is looking for “thisData” from the Arduino. Is that the string that is sent from your code above?
Thanks for the help.
Scott
Shannon
I got your code to communicate with MySQL database. I have a table set up for ID(auto-increment, primary key) TimeStamp, and thisData. The auto increment ID and TimeStamp work, but the data is not populating the table, column is there, it is just blank. I do get data on the serial monitor. I’m guessing the problem is in the php file of the database setup.
Any Ideas?
Shannon
Can you tell me where you source your cellular modules?
Thanks
Scott
Shannon
Thank you very much. This is exactly what I am wanting to do. I appreciate your willingness to help.
Scott
-
AuthorPosts