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: X_NUCLEO_IDW01M1v2-lapi-1 X_NUCLEO_IKS01A1-lapi-1
main.cpp
00001 #include "mbed.h" 00002 #include "x_nucleo_iks01a1.h" 00003 #include "SpwfInterface.h" 00004 #include "TCPSocket.h" 00005 00006 DigitalOut led1(LED1); 00007 00008 // main() runs in its own thread in the OS 00009 // (note the calls to Thread::wait below for delays) 00010 int main() { 00011 Serial pc(USBTX, USBRX); 00012 DevI2C i2c(D14, D15); 00013 HTS221 htsensor(i2c); 00014 LPS25H barosensor(i2c); 00015 00016 uint8_t sensor_id; 00017 int status = htsensor.ReadID(&sensor_id); 00018 if (status || sensor_id != I_AM_HTS221) { 00019 pc.printf("No HT sensor (status = %d id = %02x?\n", status, sensor_id); 00020 } 00021 HUM_TEMP_InitTypeDef htInitState = { 00022 .OutputDataRate = HTS221_ODR_7Hz, // This is the only one used by the init 00023 }; 00024 status = htsensor.Init(&htInitState); 00025 if (status) { 00026 pc.printf("HT init fails!\n"); 00027 } 00028 00029 status = barosensor.ReadID(&sensor_id); 00030 if (status || sensor_id != I_AM_LPS25H) { 00031 pc.printf("No Barosensor (status = %d id = %02x?\n", status, sensor_id); 00032 } 00033 00034 PRESSURE_InitTypeDef baroInitState = { 00035 // These are used in the initialization 00036 .OutputDataRate = LPS25H_ODR_7Hz, 00037 .DiffEnable = LPS25H_DIFF_DISABLE, 00038 .BlockDataUpdate = LPS25H_BDU_CONT, 00039 .SPIMode = LPS25H_SPI_SIM_4W 00040 }; 00041 status = barosensor.Init(&baroInitState); 00042 if (status) { 00043 pc.printf("Baro init fails!\n"); 00044 } 00045 00046 SpwfSAInterface wifiIf(D8, D2, /*debug*/true); 00047 Thread::wait(5000); 00048 pc.printf("Connecting...\n"); 00049 int wifiStatus = wifiIf.connect("ssid", "Pa55w0rd", NSAPI_SECURITY_WPA2, 3); 00050 00051 while (true) { 00052 led1 = !led1; 00053 float temperature = 0.0; 00054 status = htsensor.GetTemperature(&temperature); 00055 float humidity = 0.0; 00056 status |= htsensor.GetHumidity(&humidity); 00057 float pressure = 0.0; 00058 status |= barosensor.GetPressure(&pressure); 00059 float temperatureB = 0.0; 00060 status |= barosensor.GetTemperature(&temperatureB); 00061 pc.printf("Status = %d T = %.1f C RH = %.1f%% | T = %.1f C P = %.1f mbar\n", 00062 status, temperature, humidity, temperatureB, pressure); 00063 Thread::wait(15000); 00064 // pc.printf("IP address %s\n", wifiIf.get_ip_address()); 00065 } 00066 } 00067
Generated on Tue Jul 19 2022 18:24:30 by
1.7.2