Mebm  1.0.0
 All Classes Files Functions Variables Macros Pages
mebm_tut_1.ino

Tutorial number 1: Sending messages using Mebm.

Lets say we have an Arduino in the kitchen, and it has a thermometer sensor attached. We want to send a message over the network to a hypothetical destination we call the "receiverNode", telling it what the temperature is every few seconds. In this example we simulate a temperature sensor with a function which returns a random value between 0 and 50 C with the function getTemperature().

#include <SPI.h>
#include <Ethernet.h>
#include <Mebm.h>
#include <strings.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x59, 0x20 };
IPAddress thisNode(192, 168, 1, 101);
IPAddress receiverNode(192, 168, 1, 1);
char tempString[10];
void setup() {
Ethernet.begin(mac, thisNode);
Mebm.begin( "kitchen" );
}
void loop() {
delay(1000);
Mebm.sendToIP(receiverNode, "temp", getTemperature());
}
const char* getTemperature()
{
sprintf(tempString, "%d C", random(40));
return tempString;
}