![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Demo code for the DeviceHubNet library
Dependencies: DeviceHubNet TMRh20 mbed
Diff: main.cpp
- Revision:
- 0:c3057a9bb613
- Child:
- 2:74f17b595862
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 28 01:34:00 2017 +0000 @@ -0,0 +1,45 @@ +#include <mbed.h> +#include "DeviceHubNet.h" + +Serial pc(PB_6, PB_7); +DigitalOut led(PA_8); + +DeviceHubNet DHN(4275, "bbbb950b-ad0c-4fcd-8f0a-546e154a1c36", "40854b01-0ff4-407f-bc63-fa75f6604ec4"); + +void onLightSwitchMsg(uint8_t type, uint8_t ddata, float adata) +{ + pc.printf("Data received. Type: %d\n\r", type); + pc.printf("Switching light: %d\n\r", ddata); +} + +int main() +{ + led = 1; + wait_ms(2000); + + //DHN.radioPinConfig(SPI_MOSI, SPI_MISO, SPI_SCK, PB_4, PB_3); + DHN.radioPinConfig(PA_7, PA_6, PA_5, PB_3, PB_4); + DHN.radioConfig(0x1234, 100); + + pc.printf("DeviceHubNet DEMO started.\n\r\n\r"); + DHN.radioDump(); + + //uint16_t delay = DHN.radioPing(); + //pc.printf("Ping delay: %d", delay); + + uint16_t sid = DHN.registerSensor("LightSense"); + pc.printf("Sensor registered. %d\n\r", sid); + uint16_t aid = DHN.registerActuator("LightSwitch", 0, &onLightSwitchMsg); + pc.printf("Actuator registered. %d\n\r", aid); + + while (1) { + DHN.processMsgs(); + DHN.sendDigitalData(sid, 1); + wait_ms(500); + led = ! led; + DHN.sendAnalogData(sid, 3.14); + wait_ms(200); + led = ! led; + } + +} \ No newline at end of file