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: Cayenne-MQTT-mbed mbed X_NUCLEO_IDW01M1v2 NetworkSocketAPI
Diff: main.cpp
- Revision:
- 13:18b2819a1af8
- Parent:
- 12:5c663a304fca
--- a/main.cpp Tue Jul 23 01:51:31 2019 +0000
+++ b/main.cpp Fri Aug 02 05:00:44 2019 +0000
@@ -7,8 +7,6 @@
#include "CayenneMQTTClient.h"
#include "MQTTNetworkIDW01M1.h"
#include "SpwfInterface.h"
-//#include "hcsr04.h"
-//#include "Servo.h"
// WiFi network info.
char* ssid = "iPhone";
@@ -26,11 +24,10 @@
DigitalIn button1(USER_BUTTON);
DigitalOut led1(LED1);
DigitalOut ledGreen(D11);
-DigitalOut ledRed(D12);
-//HCSR04 sensor(D7, D6);
-//Servo myservo(D10);
+//DigitalOut ledRed(D12);
int iotvalue;
+//int iotvalue2;
//Function prototype new
MQTTTimer publishData(MQTTTimer, int/*, int*/);
@@ -46,28 +43,8 @@
wait(0.2);
ledGreen = iotvalue;
-
-/*ULTRASONIC + SERVO/////////////////////////////
- int openclose;
- long distance = sensor.distance();
- printf("distance %d \n",distance);
- wait(1.0); // 1 sec
- if (distance > 50) {
- ledGreen = 0;
- ledRed = 1;
- myservo = 1; //tutup
- wait(0.2);
- openclose = 0;
- }
- if (distance <50) {
- ledGreen = 1;
- ledRed = 0;
- myservo = 0; //buka
- wait(0.2);
- openclose = 1;
- }
-*/
- timer = publishData(timer, ledGreen/*, openclose*/);
+
+ timer = publishData(timer, ledGreen/*, ledRed*/);
return timer;
}
@@ -149,6 +126,16 @@
break;
}
+/* case 5:
+ // Set the onboard LED state
+ iotvalue2 = atoi(message.getValue());
+ printf("From Cayenne = %d\n",iotvalue2);
+ // Publish the updated LED state
+ if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) {
+ printf("Publish LED state failure, error: %d\n", error);
+ }
+ break;
+*/
// If this is a command message we publish a response. Here we are just sending a default 'OK' response.
// An error response should be sent if there are issues processing the message.
if ((error = mqttClient.publishResponse(message.id, NULL, message.clientID)) != CAYENNE_SUCCESS) {