Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ATParser TSL2561 mbed
main.cpp@2:8a192ca34bac, 2018-04-18 (annotated)
- Committer:
- ajwhelan
- Date:
- Wed Apr 18 14:23:01 2018 +0000
- Revision:
- 2:8a192ca34bac
- Parent:
- 1:62d78e5748b6
- Child:
- 3:9d465264c741
final?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
youngs2 | 0:c88efeed88e3 | 1 | #include "mbed.h" |
youngs2 | 0:c88efeed88e3 | 2 | #include "ATParser.h" |
youngs2 | 0:c88efeed88e3 | 3 | #include "TSL2561.h" |
youngs2 | 0:c88efeed88e3 | 4 | #include <string.h> |
youngs2 | 0:c88efeed88e3 | 5 | #include <stdlib.h> |
youngs2 | 0:c88efeed88e3 | 6 | |
youngs2 | 0:c88efeed88e3 | 7 | BufferedSerial pc(SERIAL_TX, SERIAL_RX); |
youngs2 | 0:c88efeed88e3 | 8 | BufferedSerial device(PA_9, PA_10); // tx, rx |
youngs2 | 0:c88efeed88e3 | 9 | DigitalOut myled(LED1); |
youngs2 | 0:c88efeed88e3 | 10 | TSL2561 lightsensor(PB_7,PB_6); |
youngs2 | 0:c88efeed88e3 | 11 | |
youngs2 | 0:c88efeed88e3 | 12 | int main() |
youngs2 | 0:c88efeed88e3 | 13 | { |
youngs2 | 0:c88efeed88e3 | 14 | pc.baud(115200); |
youngs2 | 0:c88efeed88e3 | 15 | device.baud(115200); |
youngs2 | 0:c88efeed88e3 | 16 | pc.printf("Hola\n\r"); |
youngs2 | 0:c88efeed88e3 | 17 | ATParser at = ATParser(device, "\n\r", 256, 2000, false); |
youngs2 | 0:c88efeed88e3 | 18 | if(at.send("AT") && at.recv("\n\r")) |
youngs2 | 0:c88efeed88e3 | 19 | { |
youngs2 | 0:c88efeed88e3 | 20 | pc.printf("Bueno#1\n\r"); |
youngs2 | 0:c88efeed88e3 | 21 | myled = !myled; |
youngs2 | 0:c88efeed88e3 | 22 | } |
youngs2 | 0:c88efeed88e3 | 23 | else |
youngs2 | 0:c88efeed88e3 | 24 | pc.printf("Nope#1\n\r"); |
youngs2 | 0:c88efeed88e3 | 25 | if(at.send("AT+NI=1,MTCDT-19400691") && 1) |
youngs2 | 0:c88efeed88e3 | 26 | pc.printf("Bueno#2\n\r"); |
youngs2 | 0:c88efeed88e3 | 27 | else |
youngs2 | 0:c88efeed88e3 | 28 | pc.printf("Nope#2\n\r"); |
youngs2 | 0:c88efeed88e3 | 29 | if(at.send("AT+NK=1,MTCDT-19400691") && 1) |
youngs2 | 0:c88efeed88e3 | 30 | pc.printf("Bueno #3\n\r"); |
youngs2 | 0:c88efeed88e3 | 31 | else |
youngs2 | 0:c88efeed88e3 | 32 | pc.printf("Nope #3\n\r"); |
youngs2 | 0:c88efeed88e3 | 33 | if(at.send("AT+FSB=1") && 1) |
youngs2 | 0:c88efeed88e3 | 34 | pc.printf("Bueno #4\n\r"); |
youngs2 | 0:c88efeed88e3 | 35 | else |
youngs2 | 0:c88efeed88e3 | 36 | pc.printf("Nope #4\n\r"); |
youngs2 | 0:c88efeed88e3 | 37 | if(at.send("AT+JOIN")&& 1) |
youngs2 | 0:c88efeed88e3 | 38 | pc.printf("Bueno #5\n\r"); |
youngs2 | 0:c88efeed88e3 | 39 | else |
youngs2 | 0:c88efeed88e3 | 40 | pc.printf("Nope #5\n\r"); |
youngs2 | 0:c88efeed88e3 | 41 | |
youngs2 | 0:c88efeed88e3 | 42 | char devID[24]; |
youngs2 | 0:c88efeed88e3 | 43 | if(at.send("AT+DI") && at.recv("%s\r\n\r\nOK", &devID)) |
youngs2 | 0:c88efeed88e3 | 44 | pc.printf("Bueno#6\n\r"); |
youngs2 | 0:c88efeed88e3 | 45 | else |
youngs2 | 0:c88efeed88e3 | 46 | pc.printf("Nope #6\n\r"); |
youngs2 | 0:c88efeed88e3 | 47 | |
youngs2 | 0:c88efeed88e3 | 48 | int i = 0; |
youngs2 | 0:c88efeed88e3 | 49 | char *day[24]; |
youngs2 | 1:62d78e5748b6 | 50 | |
youngs2 | 1:62d78e5748b6 | 51 | |
youngs2 | 0:c88efeed88e3 | 52 | while(1) |
youngs2 | 0:c88efeed88e3 | 53 | { |
youngs2 | 0:c88efeed88e3 | 54 | float lightnum = lightsensor.lux(); |
ajwhelan | 2:8a192ca34bac | 55 | pc.printf("light = %.5f\n\r", lightnum); |
youngs2 | 1:62d78e5748b6 | 56 | //char light = malloc(10); |
youngs2 | 1:62d78e5748b6 | 57 | //light = new char [8]; |
youngs2 | 1:62d78e5748b6 | 58 | day[i] = new char[8]; |
youngs2 | 1:62d78e5748b6 | 59 | int n; |
ajwhelan | 2:8a192ca34bac | 60 | n = sprintf(day[i], "%.5f", lightnum); |
youngs2 | 1:62d78e5748b6 | 61 | //pc.printf("String transfer worked: %s\n\r", day[i]); |
youngs2 | 0:c88efeed88e3 | 62 | i++; |
youngs2 | 0:c88efeed88e3 | 63 | if (i == 24) |
youngs2 | 0:c88efeed88e3 | 64 | { |
youngs2 | 0:c88efeed88e3 | 65 | int j; |
youngs2 | 0:c88efeed88e3 | 66 | for(j = 0; j < 24; j++) |
youngs2 | 0:c88efeed88e3 | 67 | { |
youngs2 | 0:c88efeed88e3 | 68 | if(at.send("AT+SEND=\"%s\"", day[j]) && 1) |
youngs2 | 1:62d78e5748b6 | 69 | { |
youngs2 | 1:62d78e5748b6 | 70 | //pc.printf("%s\n\r", day[j]); |
youngs2 | 1:62d78e5748b6 | 71 | pc.printf("success\n\r"); |
youngs2 | 1:62d78e5748b6 | 72 | //wait(.1); |
youngs2 | 1:62d78e5748b6 | 73 | } |
youngs2 | 0:c88efeed88e3 | 74 | else |
youngs2 | 0:c88efeed88e3 | 75 | pc.printf("iserox\n\r"); |
youngs2 | 0:c88efeed88e3 | 76 | } |
youngs2 | 0:c88efeed88e3 | 77 | i = 0; |
youngs2 | 0:c88efeed88e3 | 78 | for(j=0; j < 24; j++) |
youngs2 | 0:c88efeed88e3 | 79 | { |
youngs2 | 0:c88efeed88e3 | 80 | free(day[j]); |
youngs2 | 0:c88efeed88e3 | 81 | } |
youngs2 | 0:c88efeed88e3 | 82 | |
youngs2 | 0:c88efeed88e3 | 83 | } |
ajwhelan | 2:8a192ca34bac | 84 | wait(2); |
youngs2 | 0:c88efeed88e3 | 85 | } |
youngs2 | 0:c88efeed88e3 | 86 | } |