92

Dependencies:   ADXL362 ATParser MPL3115A2 TSL2561 mbed

Fork of Lab91 by Fanbo Sun

main.cpp

Committer:
fanbsun
Date:
2018-04-06
Revision:
5:4a5b8c114486
Parent:
4:eb81ef9e1621
Child:
6:074cf15af4a2

File content as of revision 5:4a5b8c114486:

#include "mbed.h"
#include "MPL3115A2.h"
#include <string>
#include <math.h>
#include <ATParser.h>
#include "BufferedSerial.h"
 
//Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
DigitalOut powerpin(PA_8); // GPIO pin
BufferedSerial pc(SERIAL_TX, SERIAL_RX);
BufferedSerial device(PA_9, PA_10);
 
// Selects SDA as I2C1_SDA on pin PB_7
// Selects SCL on I2C1_SCL on pin PB_6
// The I2C address of the pressure sensor is fixed at 0x60. 
MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
 
int main() {
    uint8_t id;
    double p, t;
    myled = 0;
    powerpin = 0;
    ATParser at = ATParser(device, "\r\n", 256, 2000, false);
    char buffer[30];
    pc.baud(115200);
    device.baud(115200);
    
    pc.printf("Hello");
    
    at.send("AT+NI=1,MTCDT-19400691\n\r");
    wait(1);
    printf("Hello");
    at.send("AT+NK=1,MTCDT-19400691\n\r");
    wait(1);
    at.send("AT+FSB=1\n\r");
    wait(1);
    at.send("AT+JOIN\n\r");
    
    while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
    {
        wait(1);
    }
    
    while(1)
    {
        wait(3600);
        p=pressure_sensor.getPressure();
        t=pressure_sensor.getTemperature();
        sprintf(buffer, "AT+SEND=%.1f,%.1f", p, t);
        buffer[18] = '\0';
        pc.printf(buffer);
        at.send(buffer);
    }
}