Created
April 23, 2012 12:36
-
-
Save Elwell/2470662 to your computer and use it in GitHub Desktop.
test MQTT flood-publish (wanted as fast as poss sending)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <NanodeUNIO.h> | |
#include <NanodeUIP.h> | |
#include <NanodeMQTT.h> | |
NanodeMQTT mqtt(&uip); | |
struct timer my_timer; | |
void setup() { | |
byte macaddr[6]; | |
NanodeUNIO unio(NANODE_MAC_DEVICE); | |
Serial.begin(38400); | |
Serial.println("MQTT Publish test"); | |
unio.read(macaddr, NANODE_MAC_ADDRESS, 6); | |
uip.init(macaddr); | |
// FIXME: use DHCP instead | |
uip.set_ip_addr(192, 168, 1, 53); | |
uip.set_gateway_addr(192, 168, 1, 1); | |
uip.set_netmask(255, 255, 255, 0); | |
uip.wait_for_link(); | |
Serial.println("Link is up"); | |
// Setup a timer - publish every 5 seconds | |
// timer_set(&my_timer, CLOCK_SECOND * 5); | |
// FIXME: resolve using DNS instead | |
//mqtt.set_server_addr(85, 119, 83, 194); | |
mqtt.set_server_addr(192, 168, 1, 251); | |
mqtt.connect(); | |
Serial.println("setup() done"); | |
} | |
int x; | |
void loop() { | |
uip.poll(); | |
// if(timer_expired(&my_timer)) { | |
// timer_reset(&my_timer); | |
if (mqtt.connected()) { | |
Serial.println("Publishing..."); | |
mqtt.publish("nanode", "I'm Alive!"); | |
Serial.println("Published."); | |
} | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment