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
- Committer:
- ajwhelan
- Date:
- 2018-04-18
- Revision:
- 3:9d465264c741
- Parent:
- 2:8a192ca34bac
- Child:
- 4:ea91348c1e16
File content as of revision 3:9d465264c741:
#include "mbed.h"
#include "ATParser.h"
#include "TSL2561.h"
#include <string.h>
#include <stdlib.h>
BufferedSerial pc(SERIAL_TX, SERIAL_RX);
BufferedSerial device(PA_9, PA_10); // tx, rx
DigitalOut myled(LED1);
TSL2561 lightsensor(PB_7,PB_6);
int main()
{
pc.baud(115200);
device.baud(115200);
pc.printf("Hola\n\r");
ATParser at = ATParser(device, "\n\r", 256, 2000, false);
if(at.send("AT") && at.recv("\n\r"))
{
pc.printf("Bueno#1\n\r");
myled = !myled;
}
else
pc.printf("Nope#1\n\r");
if(at.send("AT+NI=1,MTCDT-19400691") && 1)
pc.printf("Bueno#2\n\r");
else
pc.printf("Nope#2\n\r");
if(at.send("AT+NK=1,MTCDT-19400691") && 1)
pc.printf("Bueno #3\n\r");
else
pc.printf("Nope #3\n\r");
if(at.send("AT+FSB=1") && 1)
pc.printf("Bueno #4\n\r");
else
pc.printf("Nope #4\n\r");
if(at.send("AT+JOIN")&& 1)
pc.printf("Bueno #5\n\r");
else
pc.printf("Nope #5\n\r");
char devID[24];
if(at.send("AT+DI") && at.recv("%s\r\n\r\nOK", &devID))
pc.printf("Bueno#6\n\r");
else
pc.printf("Nope #6\n\r");
int i = 0;
char *day[24];
while(1)
{
float lightnum = lightsensor.lux();
pc.printf("light = %.5f\n\r", lightnum);
//char light = malloc(10);
//light = new char [8];
day[i] = new char[8];
int n;
n = sprintf(day[i], "%.5f", lightnum);
//pc.printf("String transfer worked: %s\n\r", day[i]);
i++;
if (i == 24)
{
int j;
for(j = 0; j < 24; j++)
{
if(at.send("AT+SEND=\"%s\"", day[j]) && 1)
{
//pc.printf("%s\n\r", day[j]);
pc.printf("success\n\r");
//wait(.1);
}
else
pc.printf("iserox\n\r");
}
i = 0;
for(j=0; j < 24; j++)
{
free(day[j]);
}
}
wait(3600);
}
}