Duy tran
/
Water_Monitor_clone_v1
Duy_new_test_Water_Monitor
Fork of Cloud_IBM_MbedOS by
Revision 3:e1f6c5af437e, committed 2017-12-05
- Comitter:
- DuyLionTran
- Date:
- Tue Dec 05 17:12:57 2017 +0000
- Parent:
- 2:e3846f091b6b
- Commit message:
- IBM_Mbed_OS_Duy_Clone
Changed in this revision
--- a/X_NUCLEO_IKS01A2.lib Fri Dec 01 11:05:04 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A2/#138a7a28bd21
--- a/X_NUCLEO_NFC01A1.lib Fri Dec 01 11:05:04 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#059115ea6ece
--- a/main.cpp Fri Dec 01 11:05:04 2017 +0100 +++ b/main.cpp Tue Dec 05 17:12:57 2017 +0000 @@ -17,8 +17,8 @@ #include "mbed.h" #include "easy-connect.h" #include "MQTTClient.h" -#include "XNucleoIKS01A2.h" -#include "XNucleoNFC01A1.h" +//#include "XNucleoIKS01A2.h" +//#include "XNucleoNFC01A1.h" #include "NDefLib/NDefNfcTag.h" #include "NDefLib/RecordType/RecordURI.h" #include "MQTTNetwork.h" @@ -31,19 +31,19 @@ //------------------------------------ static Serial pc(SERIAL_TX, SERIAL_RX); static DigitalOut myled(LED1); -static bool quickstartMode = true; // set to false to connect with authentication tocken +static bool quickstartMode = false; // set to false to connect with authentication tocken static bool BlueButtonToggle = false; -#define ORG_QUICKSTART // comment to connect to play.internetofthings.ibmcloud.com -//#define SUBSCRIBE // uncomment to subscribe to broker msgs (not to be used with IBM broker) -#define X_NUCLEO_NFC01A1_PRESENT // uncomment to add NFC support +//#define ORG_QUICKSTART // comment to connect to play.internetofthings.ibmcloud.com +#define SUBSCRIBE // uncomment to subscribe to broker msgs (not to be used with IBM broker) +//#define X_NUCLEO_NFC01A1_PRESENT // uncomment to add NFC support #define MQTT_MAX_PACKET_SIZE 400 #define MQTT_MAX_PAYLOAD_SIZE 300 // Configuration values needed to connect to IBM IoT Cloud #ifdef ORG_QUICKSTART -#define ORG "quickstart" // connect to quickstart.internetofthings.ibmcloud.com/ For a registered connection, replace with your org +#define ORG "a4nvkh" // connect to quickstart.internetofthings.ibmcloud.com/ For a registered connection, replace with your org #define ID "" #define AUTH_TOKEN "" #define DEFAULT_TYPE_NAME "iotsample-mbed-Nucleo" @@ -69,17 +69,18 @@ static bool connected = false; static int retryAttempt = 0; static char subscription_url[MQTT_MAX_PAYLOAD_SIZE]; +char topicCMD[] = "iot-2/cmd/command/fmt/json"; -static LPS22HBSensor *pressure_sensor; -static HTS221Sensor *humidity_sensor; -static HTS221Sensor *temp_sensor1; +//static LPS22HBSensor *pressure_sensor; +//static HTS221Sensor *humidity_sensor; +//static HTS221Sensor *temp_sensor1; -#ifndef TARGET_SENSOR_TILE +//#ifndef TARGET_SENSOR_TILE static void BlueButtonPressed () { BlueButtonToggle = true; } -#endif +//#endif #ifdef SUBSCRIBE void subscribe_cb(MQTT::MessageData & msgMQTT) { @@ -151,9 +152,13 @@ connected = true; printf ("--->MQTT Connected\n\r"); #ifdef SUBSCRIBE - int rc=0; - if ((rc=subscribe(MQTT_TOPIC, client)) == 0) LOG ("--->>>MQTT subscribed to: %s\n\r",MQTT_TOPIC); - else LOG ("--->>>ERROR MQTT subscribe : %s\n\r",MQTT_TOPIC); +// int rc=0; + if ((rc=subscribe(topicCMD, client)) == 0) { + LOG ("--->>>MQTT subscribed to: %s\n\r",topicCMD); + } + else { + LOG ("--->>>ERROR MQTT subscribe : %s\n\r",topicCMD); + } #endif mqttConnecting = false; connack_rc = rc; @@ -200,9 +205,12 @@ float temp, press, hum; if (!client->isConnected()) { printf ("---> MQTT DISCONNECTED\n\r"); return MQTT::FAILURE; } - temp_sensor1->get_temperature(&temp); - pressure_sensor->get_pressure(&press); - humidity_sensor->get_humidity(&hum); +// temp_sensor1->get_temperature(&temp); +// pressure_sensor->get_pressure(&press); +// humidity_sensor->get_humidity(&hum); + temp = 17.7; + press = 70.7; + hum = 80.9; sprintf(buf, "{\"d\":{\"ST\":\"Nucleo-IoT-mbed\",\"Temp\":%0.4f,\"Pressure\":%0.4f,\"Humidity\":%0.4f}}", temp, press, hum); @@ -221,24 +229,24 @@ int main() { - myled=0; - DevI2C *i2c = new DevI2C(I2C_SDA, I2C_SCL); - i2c->frequency(400000); - - XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(i2c); - pressure_sensor = mems_expansion_board->pt_sensor; - temp_sensor1 = mems_expansion_board->ht_sensor; - humidity_sensor = mems_expansion_board->ht_sensor; - pressure_sensor->enable(); - temp_sensor1->enable(); - humidity_sensor->enable(); +// myled=0; +// DevI2C *i2c = new DevI2C(I2C_SDA, I2C_SCL); +// i2c->frequency(400000); +// +// XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(i2c); +// pressure_sensor = mems_expansion_board->pt_sensor; +// temp_sensor1 = mems_expansion_board->ht_sensor; +// humidity_sensor = mems_expansion_board->ht_sensor; +// pressure_sensor->enable(); +// temp_sensor1->enable(); +// humidity_sensor->enable(); -#if !defined (TARGET_SENSOR_TILE) - InterruptIn BlueButton(USER_BUTTON); - BlueButton.fall(&BlueButtonPressed); - BlueButtonToggle = false; -#endif - +//#if !defined (TARGET_SENSOR_TILE) +// InterruptIn BlueButton(USER_BUTTON); +// BlueButton.fall(&BlueButtonPressed); + BlueButtonToggle = false; +//#endif + pc.baud(115200); pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n"); pc.printf("\r\nconnecting to AP\r\n"); @@ -297,26 +305,26 @@ int count = 0; while (true) { - if (BlueButtonToggle == false && connected == true) { + if (BlueButtonToggle == false && connected == true) { if (++count == 6) { // Publish a message every 3 second - if (publish(&client) != MQTT::SUCCESS) { - myled=0; - count=0; - client.disconnect(); - mqttNetwork.disconnect(); - attemptConnect(&client, &mqttNetwork, network); // if we have lost the connection - } else { - myled=1; - count=0; - } + if (publish(&client) != MQTT::SUCCESS) { + myled=0; + count=0; + client.disconnect(); + mqttNetwork.disconnect(); + attemptConnect(&client, &mqttNetwork, network); // if we have lost the connection + } else { + myled=1; + count=0; + } } client.yield(500); // allow the MQTT client to receive subscribe messages and manage keep alive - } else if (BlueButtonToggle == true && connected == true){ // disconnect MQTT - printf ("--->> Disconnect\n\r"); - connected = false; - count = 0; - BlueButtonToggle = false; + } else if (BlueButtonToggle == true && connected == true){ // disconnect MQTT + printf ("--->> Disconnect\n\r"); + connected = false; + count = 0; + BlueButtonToggle = false; #ifdef SUBSCRIBE // unsubscribe(const char* topicFilter); // unsubscribe if subscribed #endif
--- a/mbed_app.json Fri Dec 01 11:05:04 2017 +0100 +++ b/mbed_app.json Tue Dec 05 17:12:57 2017 +0000 @@ -2,13 +2,13 @@ "config": { "network-interface":{ "help": "options are ETHERNET, WIFI_ESP8266, WIFI_IDW0XX1, WIFI_ODIN, WIFI_RTW, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD", - "value": "WIFI_IDW0XX1" + "value": "WIFI_ESP8266" }, "wifi-ssid": { - "value": "\"SSID\"" + "value": "\"GreenLantern\"" }, "wifi-password": { - "value": "\"wifipassw\"" + "value": "\"deAlembert\"" }, "wifi-tx": { "help": "TX pin for serial connection to external device", @@ -20,13 +20,13 @@ } }, "macros": [ "MQTT_BROKER_URL=\".messaging.internetofthings.ibmcloud.com\"", - "MQTT_CLIENT_ID=\"g:pvko17:<your DEVICE_ID_TYPE>:<your DEVICE_ID>\"", - "MQTT_ORG_ID=\"93ygbc\"", + "MQTT_CLIENT_ID=\"d:a4nvkh:Nucleo_8266:PROEVN\"", + "MQTT_ORG_ID=\"a4nvkh\"", "MQTT_USERNAME=\"use-token-auth\"", - "MQTT_DEVICE_PASSWORD=\"devpassw\"", + "MQTT_DEVICE_PASSWORD=\"PROEVN2017\"", "MQTT_TOPIC=\"iot-2/evt/status/fmt/json\"", - "MQTT_DEVICE_ID=\"licio\"", - "MQTT_DEVICE_TYPE=\"envsens\"", + "MQTT_DEVICE_ID=\"PROEVN\"", + "MQTT_DEVICE_TYPE=\"Nucleo_8266\"", "MQTT_KEEPALIVE 10", "MQTT_PORT 1883", "MQTT_TLS_PORT 8883"],