example for SAKURA Internet IoT Alpha Communication Module
Dependencies: SakuraAlpha mbed
Revision 0:f18d6c77bb82, committed 2016-05-31
- Comitter:
- sakurafan
- Date:
- Tue May 31 13:41:09 2016 +0000
- Commit message:
- 1st build;
Changed in this revision
diff -r 000000000000 -r f18d6c77bb82 SakuraAlpha.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SakuraAlpha.lib Tue May 31 13:41:09 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/sakurafan/code/SakuraAlpha/#38f4d6047886
diff -r 000000000000 -r f18d6c77bb82 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue May 31 13:41:09 2016 +0000 @@ -0,0 +1,81 @@ +/* SAKURA Internet IoT Alpha Communication Module + * + * Copyright (c) SAKURA Internet Inc. + * The MIT License (MIT) + * https://github.com/sakura-internet/SakuraAlphaArduino + * + * https://iot.sakura.ad.jp/ + * + * Porting to mbed by sakurafan. 2016 + */ + +#include "mbed.h" +#include "SakuraAlpha.h" + +#define BUF_LEN 16 + +SakuraAlphaSPI sakura(p5, p6, p7, p8); // mosi, miso, sclk, cs +/* +SPI spi(p5, p6, p7); // mosi, miso, sclk +SakuraAlphaSPI sakura(spi, p8); // spi, cs +*/ +Serial pc(USBTX, USBRX); +DigitalOut myled(LED1); + +int main () { + uint32_t cnt = 0; + uint8_t updated[BUF_LEN]; + + pc.baud(115200); + pc.printf("Waiting to come online...\r\n"); + + for(;;){ + if( sakura.getNetworkStatus() == 1 ) break; + myled = !myled; + wait_ms(1000); + } + myled = 1; + + for (;;) { + cnt++; + pc.printf("%d\r\n", cnt); + sakura.writeChannel(0,cnt); + sakura.writeChannel(1,cnt); + sakura.writeChannel(2,cnt); + wait_ms(250); + + int num_updated = sakura.getUpdatedChannels(updated, BUF_LEN); + pc.printf("%d updated channels: ", num_updated); + for (int i = 0; i < min(num_updated,BUF_LEN); i++) { + pc.printf(" %d", updated[i]); + } + pc.printf("\r\n"); + + char type=0; + uint8_t value[8]={0}; + + sakura.readChannel(0, &type, value); + + for (int i = 0; i < 8; i++) { + pc.printf(" %x", value[i]); + } + + pc.printf(" type: %d\r\n", type); + wait_ms(250); + + pc.printf("Tx[0] status: %d\r\n", sakura.getTxChannelStatus(0)); + + sakura.transmit(TRANSMIT_ONCE); + wait_ms(250); + + num_updated = sakura.getUntransmittedChannels(updated, BUF_LEN); + pc.printf("%d untransmitted channels: ", num_updated); + for (int i = 0; i < min(num_updated,BUF_LEN); i++) { + pc.printf(" %d", updated[i]); + } + pc.printf("\r\n"); + wait_ms(1000); + + pc.printf("\r\n"); + } +}
diff -r 000000000000 -r f18d6c77bb82 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue May 31 13:41:09 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file