![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Demo code for the DeviceHubNet library
Dependencies: DeviceHubNet TMRh20 mbed
main.cpp@0:c3057a9bb613, 2017-03-28 (annotated)
- Committer:
- gume
- Date:
- Tue Mar 28 01:34:00 2017 +0000
- Revision:
- 0:c3057a9bb613
- Child:
- 2:74f17b595862
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gume | 0:c3057a9bb613 | 1 | #include <mbed.h> |
gume | 0:c3057a9bb613 | 2 | #include "DeviceHubNet.h" |
gume | 0:c3057a9bb613 | 3 | |
gume | 0:c3057a9bb613 | 4 | Serial pc(PB_6, PB_7); |
gume | 0:c3057a9bb613 | 5 | DigitalOut led(PA_8); |
gume | 0:c3057a9bb613 | 6 | |
gume | 0:c3057a9bb613 | 7 | DeviceHubNet DHN(4275, "bbbb950b-ad0c-4fcd-8f0a-546e154a1c36", "40854b01-0ff4-407f-bc63-fa75f6604ec4"); |
gume | 0:c3057a9bb613 | 8 | |
gume | 0:c3057a9bb613 | 9 | void onLightSwitchMsg(uint8_t type, uint8_t ddata, float adata) |
gume | 0:c3057a9bb613 | 10 | { |
gume | 0:c3057a9bb613 | 11 | pc.printf("Data received. Type: %d\n\r", type); |
gume | 0:c3057a9bb613 | 12 | pc.printf("Switching light: %d\n\r", ddata); |
gume | 0:c3057a9bb613 | 13 | } |
gume | 0:c3057a9bb613 | 14 | |
gume | 0:c3057a9bb613 | 15 | int main() |
gume | 0:c3057a9bb613 | 16 | { |
gume | 0:c3057a9bb613 | 17 | led = 1; |
gume | 0:c3057a9bb613 | 18 | wait_ms(2000); |
gume | 0:c3057a9bb613 | 19 | |
gume | 0:c3057a9bb613 | 20 | //DHN.radioPinConfig(SPI_MOSI, SPI_MISO, SPI_SCK, PB_4, PB_3); |
gume | 0:c3057a9bb613 | 21 | DHN.radioPinConfig(PA_7, PA_6, PA_5, PB_3, PB_4); |
gume | 0:c3057a9bb613 | 22 | DHN.radioConfig(0x1234, 100); |
gume | 0:c3057a9bb613 | 23 | |
gume | 0:c3057a9bb613 | 24 | pc.printf("DeviceHubNet DEMO started.\n\r\n\r"); |
gume | 0:c3057a9bb613 | 25 | DHN.radioDump(); |
gume | 0:c3057a9bb613 | 26 | |
gume | 0:c3057a9bb613 | 27 | //uint16_t delay = DHN.radioPing(); |
gume | 0:c3057a9bb613 | 28 | //pc.printf("Ping delay: %d", delay); |
gume | 0:c3057a9bb613 | 29 | |
gume | 0:c3057a9bb613 | 30 | uint16_t sid = DHN.registerSensor("LightSense"); |
gume | 0:c3057a9bb613 | 31 | pc.printf("Sensor registered. %d\n\r", sid); |
gume | 0:c3057a9bb613 | 32 | uint16_t aid = DHN.registerActuator("LightSwitch", 0, &onLightSwitchMsg); |
gume | 0:c3057a9bb613 | 33 | pc.printf("Actuator registered. %d\n\r", aid); |
gume | 0:c3057a9bb613 | 34 | |
gume | 0:c3057a9bb613 | 35 | while (1) { |
gume | 0:c3057a9bb613 | 36 | DHN.processMsgs(); |
gume | 0:c3057a9bb613 | 37 | DHN.sendDigitalData(sid, 1); |
gume | 0:c3057a9bb613 | 38 | wait_ms(500); |
gume | 0:c3057a9bb613 | 39 | led = ! led; |
gume | 0:c3057a9bb613 | 40 | DHN.sendAnalogData(sid, 3.14); |
gume | 0:c3057a9bb613 | 41 | wait_ms(200); |
gume | 0:c3057a9bb613 | 42 | led = ! led; |
gume | 0:c3057a9bb613 | 43 | } |
gume | 0:c3057a9bb613 | 44 | |
gume | 0:c3057a9bb613 | 45 | } |