
In this lab, you will be collecting light data with your sensor and sending it wirelessly over the lora network to the server. In this lab you will: Utilize the system that you created for lab 9 to collect light data. Collect a light sample each hour for 24 hours. Send the 24 samples 1 time per day. Run your system over a period of 2 days in Luddy 4150 to collect light data on this room.
Dependencies: ATParser TSL2561 mbed
Revision 2:ac9f576fbcb7, committed 2018-04-19
- Comitter:
- csinders
- Date:
- Thu Apr 19 14:54:48 2018 +0000
- Parent:
- 1:fb25b13e6ab3
- Commit message:
- Have it set up using DR1. 6 transmissions with 4 data points each.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fb25b13e6ab3 -r ac9f576fbcb7 main.cpp --- a/main.cpp Tue Apr 17 14:54:18 2018 +0000 +++ b/main.cpp Thu Apr 19 14:54:48 2018 +0000 @@ -71,6 +71,21 @@ i++; } } +/* +Copies copyFrom into the CopyTo string. +/StartTo is the starting index of Copyto +copyFromSize is the size of the string being copied +//EX: Copyfrom = "HI", Copyto = "____", startTo = 1, copyFromSize = 2 +// end result of copyTo = "_HI_" +*/ +void copyString(char *copyTo, char *copyFrom, int startTo, int copyFromSize) { + int i; + for (i = 0; i < copyFromSize; i++) { + copyTo[i+startTo] = copyFrom[i]; + } +} + + int main() { pc.baud(115200); device.baud(115200); @@ -78,12 +93,16 @@ wait(1); myled = 0; + //Array to hold data + int dataArraySize = 24; + int lightBufSize = 8; + char dataArray[dataArraySize][lightBufSize]; + pc.printf("Starting program\n\r"); if (!sendAtMessage("AT\n")) { pc.printf("xDot not responding to message\n\r"); } - //Try to connect xDot to network // Provice network name char networkName[] = "AT+NI=1,MTCDT-19400691\n"; if (!sendAtMessage(networkName)) { @@ -100,82 +119,55 @@ pc.printf("Network frequency SubBand not successfully set\n\r"); } - - if (!sendAtMessage("AT+TXDR=2\n")) { + //Set data transmission rate + if (!sendAtMessage("AT+TXDR=1\n")) { pc.printf("Unable to set dataRate\n\r"); } - pc.printf("I got here\r\n"); + if (!sendAtMessage("AT+ACK=8\n")) { + pc.printf("Unable to set acknowledgement requirement\n\r"); + } + pc.printf("I got here\n\r"); //Join the network char joinNetwork[] = "AT+JOIN\n"; // Unable to join network atm. - if (!sendAtMessage(joinNetwork)) { + while (!sendAtMessage(joinNetwork)) { pc.printf("Failed to joined the network\n\r"); - } - - - - int i = 0; - while(1) { - sendAtMessageNACK("AT+SEND=",8); - for (i = 0; i < 5; i++) { - int lightBufSize = 10; - double light = lightsensor.lux(); - char lightBuf[lightBufSize]; - pc.printf("Current light is %f\n\r",light); - sprintf(lightBuf, "%3.5f",light); - pc.printf("After convert with sprintf light = %s\n\r",lightBuf); - sendAtMessageNACK(lightBuf,lightBufSize); - sendAtMessageNACK(",",1); - wait(1); - } - if (sendAtMessage("\n")) { - pc.printf("message succesfully sent\n\r"); - myled = 1; - } else { - pc.printf("Failed to send the message for some reason\r\n"); - } + wait(1); } + while (!sendAtMessage("AT+SEND=TestMessage\n")) { + myled=0; + } + myled = 1; - //When an s is read from the serial pc, - // read the current pressure/temperature from the I2C pressure sensor - // and send it to the MQTT server pivot.iuiot - //Unsure of what size to set Buffer so that it doesn't go over - //when trying to send a message - - /* while(1) { - if (pc.readable()) { - //pc.printf("pc.readable\r\n"); - if (pc.getc() == 's') { - pc.printf("I recieved an s\r\n"); - int tempBufSize = 4; - int presBufSize = 6; - double temp = pressure_sensor.getTemperature(); - char tempBuf[tempBufSize]; - double pres = pressure_sensor.getPressure(); - char presBuf[presBufSize]; - pc.printf("Current temp is %f\n\r",temp); - pc.printf("Current pres is %f\n\r",pres); - sprintf(tempBuf, "%2.1f",temp); - sprintf(presBuf, "%4.1f",pres); - pc.printf("After convert with sprintf temp = %s\n\r",tempBuf); - pc.printf("After convert with sprintf pres = %s\n\r",presBuf); - sendAtMessageNACK("AT+SEND=",8); - sendAtMessageNACK(tempBuf,tempBufSize); - sendAtMessageNACK(",",1); - sendAtMessageNACK(presBuf,presBufSize); - wait_ms(500); - if (sendAtMessage("\n")) { - pc.printf("message succesfully sent\n\r"); - } else { - pc.printf("Failed to send the message for some reason\r\n"); - } + //Collect data + int i = 0; + for (i = 0; i < dataArraySize; i++) { + double light = lightsensor.lux(); + pc.printf("Current light is %f\n\r",light); + sprintf(dataArray[i], "%2.5f",light); + pc.printf("After convert with sprintf light = %s\n\r",dataArray[i]); + wait_ms(500); + } + //pc.printf("%s\n\r",dataArray); + + + for (i = 0; i < 6; i++) { + int j; + sendAtMessageNACK("AT+SEND=",8); + for (j = 0; j < 4; j++) { + sendAtMessageNACK(dataArray[(i*4) + j], lightBufSize); + sendAtMessageNACK(";",1); } + if(sendAtMessage("\n")) { + pc.printf("message succesfully sent\n\r"); + //myled = 1; + } + wait_ms(1000); } } - */ while(1) {