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: C12832 EthernetInterface MMA7660 MQTT USBDevice mbed-rtos mbed
Fork of HelloMQTT by
Revision 20:63e59fe8d75d, committed 2016-05-09
- Comitter:
- co838_pg297
- Date:
- Mon May 09 20:46:07 2016 +0000
- Parent:
- 19:7f7aba7a4a8b
- Commit message:
- the code of obtain senor data and connect to MQTT
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Mon May 09 20:46:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Mon May 09 20:46:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#d17693b10ae6
--- a/main.cpp Thu Jul 30 13:49:18 2015 +0000
+++ b/main.cpp Mon May 09 20:46:07 2016 +0000
@@ -1,31 +1,4 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- * Ian Craggs - make sure QoS2 processing works, and add device headers
- *******************************************************************************/
-
- /**
- This is a sample program to illustrate the use of the MQTT Client library
- on the mbed platform. The Client class requires two classes which mediate
- access to system interfaces for networking and timing. As long as these two
- classes provide the required public programming interfaces, it does not matter
- what facilities they use underneath. In this program, they use the mbed
- system libraries.
-
- */
-
- // change this to 0 to output messages to serial instead of LCD
+
#define USE_LCD 1
#if USE_LCD
@@ -50,6 +23,11 @@
#include "MQTTEthernet.h"
#include "MQTTClient.h"
+#include "USBSerial.h"
+#include "C12832.h"
+#include "MMA7660.h"
+
+MMA7660 MMA(D14, D15);
int arrivedcount = 0;
@@ -63,17 +41,33 @@
}
-int main(int argc, char* argv[])
+int main(int argc, char* argv[],float c,float ang)
{
+ lcd.cls();
+ lcd.locate(0,3);
+ printf("mbed application shield!");
+
+
+
+ while(1) {
+ wait(0.1f);
+ lcd.locate(0,14);
+ float c=MMA.y()/MMA.z();
+ float ang=pow(c,(-1));
+ printf("%.2f,%.2f,%.2f",MMA.x(),MMA.y(),MMA.z());
+ printf("%.2f",ang);
+
+ }
+ if (ang<=-1){
MQTTEthernet ipstack = MQTTEthernet();
float version = 0.5;
- char* topic = "mbed-sample";
+ char* topic = "door";
printf("HelloMQTT: version is %f\n", version);
MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
- char* hostname = "m2m.eclipse.org";
+ char* hostname = "doughnut.kent.ac.uk";
int port = 1883;
printf("Connecting to %s:%d\n", hostname, port);
int rc = ipstack.connect(hostname, port);
@@ -95,7 +89,7 @@
// QoS 0
char buf[100];
- sprintf(buf, "Hello World! QoS 0 message from app version %f\n", version);
+ sprintf(buf, "door opened %f\n", version);
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
@@ -105,21 +99,7 @@
while (arrivedcount < 1)
client.yield(100);
- // QoS 1
- sprintf(buf, "Hello World! QoS 1 message from app version %f\n", version);
- message.qos = MQTT::QOS1;
- message.payloadlen = strlen(buf)+1;
- rc = client.publish(topic, message);
- while (arrivedcount < 2)
- client.yield(100);
-
- // QoS 2
- sprintf(buf, "Hello World! QoS 2 message from app version %f\n", version);
- message.qos = MQTT::QOS2;
- message.payloadlen = strlen(buf)+1;
- rc = client.publish(topic, message);
- while (arrivedcount < 3)
- client.yield(100);
+
if ((rc = client.unsubscribe(topic)) != 0)
printf("rc from unsubscribe was %d\n", rc);
@@ -133,3 +113,4 @@
return 0;
}
+}
