lab10

Dependencies:   ATParser TSL2561 mbed

Committer:
kmhatre
Date:
Sat Apr 28 01:16:30 2018 +0000
Revision:
0:b07143777915
lab10;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kmhatre 0:b07143777915 1 #include "mbed.h"
kmhatre 0:b07143777915 2 #include "ATParser.h"
kmhatre 0:b07143777915 3 #include "TSL2561.h"
kmhatre 0:b07143777915 4 #include <string>
kmhatre 0:b07143777915 5 #include <algorithm>
kmhatre 0:b07143777915 6 #include <iostream>
kmhatre 0:b07143777915 7
kmhatre 0:b07143777915 8
kmhatre 0:b07143777915 9
kmhatre 0:b07143777915 10
kmhatre 0:b07143777915 11
kmhatre 0:b07143777915 12 BufferedSerial pc(SERIAL_TX, SERIAL_RX);
kmhatre 0:b07143777915 13 BufferedSerial dev(PA_9, PA_10);
kmhatre 0:b07143777915 14 DigitalOut myled(LED1);
kmhatre 0:b07143777915 15 TSL2561 light_sensor(PB_7, PB_6);
kmhatre 0:b07143777915 16
kmhatre 0:b07143777915 17
kmhatre 0:b07143777915 18
kmhatre 0:b07143777915 19 int main() {
kmhatre 0:b07143777915 20 pc.baud(115200);
kmhatre 0:b07143777915 21 dev.baud(115200);
kmhatre 0:b07143777915 22
kmhatre 0:b07143777915 23 ATParser at = ATParser(dev, "\r\n");
kmhatre 0:b07143777915 24
kmhatre 0:b07143777915 25 printf("Program Started\n\r");
kmhatre 0:b07143777915 26
kmhatre 0:b07143777915 27 pc.printf("\n\rConnecting Lora\n\r");
kmhatre 0:b07143777915 28 if (at.send("AT")) {
kmhatre 0:b07143777915 29 if(at.recv("OK")){
kmhatre 0:b07143777915 30 pc.printf("Lora Device Working\r\n");
kmhatre 0:b07143777915 31 }
kmhatre 0:b07143777915 32 else {
kmhatre 0:b07143777915 33 pc.printf("Lora Device NOT Working\r\n");
kmhatre 0:b07143777915 34 }
kmhatre 0:b07143777915 35 }
kmhatre 0:b07143777915 36 if (at.send("AT+NI=1,MTCDT-19400691")) {
kmhatre 0:b07143777915 37 if(at.recv("OK")){
kmhatre 0:b07143777915 38 pc.printf("Network ID Working\r\n");
kmhatre 0:b07143777915 39 }
kmhatre 0:b07143777915 40 else {
kmhatre 0:b07143777915 41 pc.printf("Network ID NOT Working\r\n");
kmhatre 0:b07143777915 42 }
kmhatre 0:b07143777915 43 }
kmhatre 0:b07143777915 44 if (at.send("AT+NK=1,MTCDT-19400691")) {
kmhatre 0:b07143777915 45 if(at.recv("OK")){
kmhatre 0:b07143777915 46 pc.printf("Network Key Working\r\n");
kmhatre 0:b07143777915 47 }
kmhatre 0:b07143777915 48 else {
kmhatre 0:b07143777915 49 pc.printf("Network Key NOT Working\r\n");
kmhatre 0:b07143777915 50 }
kmhatre 0:b07143777915 51 }
kmhatre 0:b07143777915 52 if (at.send("AT+FSB=1")) {
kmhatre 0:b07143777915 53 if(at.recv("OK")){
kmhatre 0:b07143777915 54 pc.printf("Frequency Sub Band set to 1\r\n");
kmhatre 0:b07143777915 55 }
kmhatre 0:b07143777915 56 else {
kmhatre 0:b07143777915 57 pc.printf("Frequency Sub Band NOT set\r\n");
kmhatre 0:b07143777915 58 }
kmhatre 0:b07143777915 59 }
kmhatre 0:b07143777915 60 if (at.send("AT+JOIN")) {
kmhatre 0:b07143777915 61 if(at.recv("OK")){
kmhatre 0:b07143777915 62 pc.printf("Successfully joined network\r\n");
kmhatre 0:b07143777915 63 }
kmhatre 0:b07143777915 64 else {
kmhatre 0:b07143777915 65 pc.printf("ERROR Unable to join Network\r\n");
kmhatre 0:b07143777915 66 }
kmhatre 0:b07143777915 67 }
kmhatre 0:b07143777915 68 int i = 0;
kmhatre 0:b07143777915 69 while(1) {
kmhatre 0:b07143777915 70 float data[24];
kmhatre 0:b07143777915 71 if(i == 24) {
kmhatre 0:b07143777915 72 char dataS[3200];
kmhatre 0:b07143777915 73 sprintf(dataS, "%3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23]);
kmhatre 0:b07143777915 74 at.send("AT+SEND=\"%s\"", dataS);
kmhatre 0:b07143777915 75 i = 0;
kmhatre 0:b07143777915 76 }
kmhatre 0:b07143777915 77 float light = light_sensor.lux();
kmhatre 0:b07143777915 78 data[i] = light;
kmhatre 0:b07143777915 79 pc.printf("%f\n\r", data[i]);
kmhatre 0:b07143777915 80 i++;
kmhatre 0:b07143777915 81 wait(3600);
kmhatre 0:b07143777915 82 }
kmhatre 0:b07143777915 83 }