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: ADXL362 ATParser MPL3115A2 TSL2561 mbed
Fork of Lab91 by
Revision 8:a3f81e46a122, committed 2018-04-24
- Comitter:
- fanbsun
- Date:
- Tue Apr 24 14:51:33 2018 +0000
- Parent:
- 6:074cf15af4a2
- Commit message:
- 1
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Apr 20 16:01:07 2018 +0000
+++ b/main.cpp Tue Apr 24 14:51:33 2018 +0000
@@ -1,15 +1,16 @@
#include "mbed.h"
#include "MPL3115A2.h"
-#include <string>
+#include <string.h>
#include <math.h>
#include <ATParser.h>
#include "BufferedSerial.h"
#include "TSL2561.h"
+
//Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
DigitalOut powerpin(PA_8); // GPIO pin
-//BufferedSerial pc(SERIAL_TX, SERIAL_RX);
+BufferedSerial pc(SERIAL_TX, SERIAL_RX);
BufferedSerial device(PA_9, PA_10);
// Selects SDA as I2C1_SDA on pin PB_7
@@ -24,35 +25,53 @@
double p, t, l;
myled = 0;
powerpin = 0;
+ char s[6];
ATParser at = ATParser(device, "\r\n", 256, 2000, false);
- char buffer[30];
+ char buffer[200];
char buffer1[30];
-// pc.baud(115200);
+ pc.baud(115200);
device.baud(115200);
- // pc.printf("Hello");
+ pc.printf("Hello");
at.send("AT+NI=1,MTCDT-19400691\n\r") && at.recv("OK");
at.send("AT+NK=1,MTCDT-19400691\n\r") && at.recv("OK");
at.send("AT+FSB=1\n\r") && at.recv("OK");
at.send("AT+JOIN\n\r") && at.recv("OK");
-
+ at.send("AT+TXDR=7\n\r") && at.recv("OK");
+
+
+
while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
{
wait(1);
}
+ strcpy(buffer, "AT+SEND=");
+
while(1)
{
- l=lightsensor.lux();
- p=pressure_sensor.getPressure();
- t=pressure_sensor.getTemperature();
- sprintf(buffer1, "AT+SEND=%.4f\n\r", l);
- sprintf(buffer, "AT+SEND=%.1f,%.1f\n\r", p, t);
- buffer[20] = '\0';
+ for(int i = 0; i< 24; i++)
+ {
+ l=lightsensor.lux();
+ sprintf(s, "%.1f", l);
+ strcat(buffer, s);
+ strcat(buffer, ",");
+ pc.printf(buffer);
+ pc.printf("\n\r");
+ wait(5);
+ }
+
+
+
+
+ // p=pressure_sensor.getPressure();
+ // t=pressure_sensor.getTemperature();
+ // sprintf(buffer1, "AT+SEND=a\n\r");
+ // sprintf(buffer, "AT+SEND=%.1f,%.1f\n\r", p, t);
// pc.printf(buffer);
at.send(buffer) && at.recv("OK");
- at.send(buffer1) && at.recv("OK");
+ // at.send(buffer1) && at.recv("OK");
wait(10);
}
}
\ No newline at end of file
