Application testing co-operation of X-NUCLEO boards IKS01A1 (sensors) and IDW01M1 (wifi)

Dependencies:   X_NUCLEO_IDW01M1v2-lapi-1 X_NUCLEO_IKS01A1-lapi-1

Committer:
lapi
Date:
Sun Nov 20 20:35:23 2016 +0000
Revision:
0:e3e4af4648ab
Application testing co-operation between X-NUCLEO boards IKS01A1 (sensors) and IDW01M1 (wifi)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lapi 0:e3e4af4648ab 1 #include "mbed.h"
lapi 0:e3e4af4648ab 2 #include "x_nucleo_iks01a1.h"
lapi 0:e3e4af4648ab 3 #include "SpwfInterface.h"
lapi 0:e3e4af4648ab 4 #include "TCPSocket.h"
lapi 0:e3e4af4648ab 5
lapi 0:e3e4af4648ab 6 DigitalOut led1(LED1);
lapi 0:e3e4af4648ab 7
lapi 0:e3e4af4648ab 8 // main() runs in its own thread in the OS
lapi 0:e3e4af4648ab 9 // (note the calls to Thread::wait below for delays)
lapi 0:e3e4af4648ab 10 int main() {
lapi 0:e3e4af4648ab 11 Serial pc(USBTX, USBRX);
lapi 0:e3e4af4648ab 12 DevI2C i2c(D14, D15);
lapi 0:e3e4af4648ab 13 HTS221 htsensor(i2c);
lapi 0:e3e4af4648ab 14 LPS25H barosensor(i2c);
lapi 0:e3e4af4648ab 15
lapi 0:e3e4af4648ab 16 uint8_t sensor_id;
lapi 0:e3e4af4648ab 17 int status = htsensor.ReadID(&sensor_id);
lapi 0:e3e4af4648ab 18 if (status || sensor_id != I_AM_HTS221) {
lapi 0:e3e4af4648ab 19 pc.printf("No HT sensor (status = %d id = %02x?\n", status, sensor_id);
lapi 0:e3e4af4648ab 20 }
lapi 0:e3e4af4648ab 21 HUM_TEMP_InitTypeDef htInitState = {
lapi 0:e3e4af4648ab 22 .OutputDataRate = HTS221_ODR_7Hz, // This is the only one used by the init
lapi 0:e3e4af4648ab 23 };
lapi 0:e3e4af4648ab 24 status = htsensor.Init(&htInitState);
lapi 0:e3e4af4648ab 25 if (status) {
lapi 0:e3e4af4648ab 26 pc.printf("HT init fails!\n");
lapi 0:e3e4af4648ab 27 }
lapi 0:e3e4af4648ab 28
lapi 0:e3e4af4648ab 29 status = barosensor.ReadID(&sensor_id);
lapi 0:e3e4af4648ab 30 if (status || sensor_id != I_AM_LPS25H) {
lapi 0:e3e4af4648ab 31 pc.printf("No Barosensor (status = %d id = %02x?\n", status, sensor_id);
lapi 0:e3e4af4648ab 32 }
lapi 0:e3e4af4648ab 33
lapi 0:e3e4af4648ab 34 PRESSURE_InitTypeDef baroInitState = {
lapi 0:e3e4af4648ab 35 // These are used in the initialization
lapi 0:e3e4af4648ab 36 .OutputDataRate = LPS25H_ODR_7Hz,
lapi 0:e3e4af4648ab 37 .DiffEnable = LPS25H_DIFF_DISABLE,
lapi 0:e3e4af4648ab 38 .BlockDataUpdate = LPS25H_BDU_CONT,
lapi 0:e3e4af4648ab 39 .SPIMode = LPS25H_SPI_SIM_4W
lapi 0:e3e4af4648ab 40 };
lapi 0:e3e4af4648ab 41 status = barosensor.Init(&baroInitState);
lapi 0:e3e4af4648ab 42 if (status) {
lapi 0:e3e4af4648ab 43 pc.printf("Baro init fails!\n");
lapi 0:e3e4af4648ab 44 }
lapi 0:e3e4af4648ab 45
lapi 0:e3e4af4648ab 46 SpwfSAInterface wifiIf(D8, D2, /*debug*/true);
lapi 0:e3e4af4648ab 47 Thread::wait(5000);
lapi 0:e3e4af4648ab 48 pc.printf("Connecting...\n");
lapi 0:e3e4af4648ab 49 int wifiStatus = wifiIf.connect("ssid", "Pa55w0rd", NSAPI_SECURITY_WPA2, 3);
lapi 0:e3e4af4648ab 50
lapi 0:e3e4af4648ab 51 while (true) {
lapi 0:e3e4af4648ab 52 led1 = !led1;
lapi 0:e3e4af4648ab 53 float temperature = 0.0;
lapi 0:e3e4af4648ab 54 status = htsensor.GetTemperature(&temperature);
lapi 0:e3e4af4648ab 55 float humidity = 0.0;
lapi 0:e3e4af4648ab 56 status |= htsensor.GetHumidity(&humidity);
lapi 0:e3e4af4648ab 57 float pressure = 0.0;
lapi 0:e3e4af4648ab 58 status |= barosensor.GetPressure(&pressure);
lapi 0:e3e4af4648ab 59 float temperatureB = 0.0;
lapi 0:e3e4af4648ab 60 status |= barosensor.GetTemperature(&temperatureB);
lapi 0:e3e4af4648ab 61 pc.printf("Status = %d T = %.1f C RH = %.1f%% | T = %.1f C P = %.1f mbar\n",
lapi 0:e3e4af4648ab 62 status, temperature, humidity, temperatureB, pressure);
lapi 0:e3e4af4648ab 63 Thread::wait(15000);
lapi 0:e3e4af4648ab 64 // pc.printf("IP address %s\n", wifiIf.get_ip_address());
lapi 0:e3e4af4648ab 65 }
lapi 0:e3e4af4648ab 66 }
lapi 0:e3e4af4648ab 67