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: EthernetInterface MQTT Servo mbed-rtos mbed
Fork of MQTTPublishSubcribe by
Revision 20:d029102c00fa, committed 2015-04-06
- Comitter:
- stefan1691
- Date:
- Mon Apr 06 06:57:40 2015 +0000
- Parent:
- 19:65884a321e48
- Commit message:
- Servo integriert
Changed in this revision
| Servo.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Mon Apr 06 06:57:40 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/main.cpp Sat Apr 04 17:11:43 2015 +0000
+++ b/main.cpp Mon Apr 06 06:57:40 2015 +0000
@@ -1,9 +1,10 @@
-/** MQTT Subscribe und Publish
+/** MQTT Subscribe und Publish
Wartet auf eine Publish Nachricht und sendet
dann die dazugehoerende Nachricht zurueck */
#include "mbed.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"
+#include "Servo.h"
// UI
DigitalOut led1( LED1 );
@@ -11,6 +12,8 @@
AnalogIn poti( A0 );
// Licht Sensor
AnalogIn light( A1 );
+// Servos
+Servo servo1 ( D9 );
// MQTT Brocker
//char* hostname = "iot.eclipse.org";
@@ -47,11 +50,13 @@
/** Daten empfangen von MQTT Broker */
void messageArrived( MQTT::MessageData& md )
{
+ float value;
MQTT::Message &message = md.message;
printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id);
printf("Topic %.*s, ", md.topicName.lenstring.len, (char*) md.topicName.lenstring.data );
printf("Payload %.*s\n", message.payloadlen, (char*) message.payload);
+ // Sensoren
// in C sind Zeiger auf char immer Positionsangaben, deshalb sind Additionen und Subtraktionen moeglich.
if ( strncmp( (char*) md.topicName.lenstring.data + md.topicName.lenstring.len - 4, "poti", 4 ) == 0 )
{
@@ -62,7 +67,15 @@
{
printf( "Light %f\n", light.read() );
publish( topicLight, light.read() );
- }
+ }
+
+ // Aktoren
+ if ( strncmp( (char*) md.topicName.lenstring.data + md.topicName.lenstring.len - 6, "servo1", 6) == 0 )
+ {
+ sscanf( (char*) message.payload, "%f", &value );
+ servo1 = value;
+ printf( "Servo1 %f\n", value );
+ }
}
int main()
