XBee-mbed library - XBee APIモードライブラリ

XBee-mbed library

This library has been ported from the XBee-Arduino..

for Series 1, Series 2 (and DigiMesh), Wi-Fi

AP=2 API ENABLE (use escape characters)

アナログ値取得、バグ修正済み

※ XBee Wi-Fi のために少し拡張
※ XBee Wi-Fi は、単に無線部をWi-Fiに置き換えたというもので、あくまでXBeeである。 (汎用的に使えるWi-Fiモジュールが欲しければ、Gainspan社のTELEC認証済みモジュールが有力か)


mbedの下駄シリーズ、積み重ね基板にXBeeを搭載できます。

Series_1/2

	+--------+             +--------+
	|  mbed  |3.3V------VCC|1  XBee |
	|        |             |        |
	|     p14|RX-------DOUT|2   S1  |
	|     p13|TX--------DIN|3   or  |
	|        |             |    S2  |
	|        |GND-------GND|10      |
	+--------+             +--------+

WiFi

	+--------+             +--------+
	|  mbed  |3.3V------VCC|1  XBee |
	|        |             |        |
	|     p14|RX-------DOUT|2       |
	|     p13|TX--------DIN|3       |
	|        |             |    WiFi|
	|   P0_22|RTS-------RTS|16      |
	|     p12|CTS-------CTS|12      |
	|        |             |        |
	|        |GND-------GND|10      |
	+--------+             +--------+

※ Wi-Fiはハードウェアフロー制御が必須。(確実にデータを取りこぼす)

Documents

Download

Import libraryXBee

XBee-mbed library http://mbed.org/users/okini3939/notebook/xbee-mbed/

Sample

リモートのXBeeのポートに取り付けたLEDを点滅させる。(X-CTU設定:AP=2)

Import programXBee_sample

XBee-mbed sample

sample

#include "mbed.h"
#include "XBee.h"

XBee xbee(p13, p14);

int main() {
    uint8_t Cmd[] = {'D', '4'};
    uint8_t Val[] = {0x04};
    XBeeAddress64 remoteAddress(0x0013A200, 0x40319F25);
    RemoteAtCommandRequest remoteAtRequest;

    wait(1);
    xbee.begin(9800);

    remoteAtRequest = RemoteAtCommandRequest(remoteAddress, Cmd, Low, sizeof(Low));
    remoteAtRequest.setApplyChanges(true);

    remoteAtRequest.setCommandValue(Val);
    remoteAtRequest.setCommandValueLength(sizeof(Val));
    xbee.send(remoteAtRequest);
}

Wi-Fiの無線LANアクセスポイント接続とHTTP GETのサンプル。(X-CTU設定:AP=2、BD=7)

DNS lookup も実装してみたがうまく動かない。(下記 Note 参照)

Import programXBee_wifi_sample

http://mbed.org/users/okini3939/notebook/xbee-mbed/

sample

#include "mbed.h"
#include "XBeeWiFi.h"

XBeeWiFi xbee(p13, p14, p21); // TX, RX, CTS

void main () {
    IPv4TransmitRequest data;
    uint8_t buf[100];
      :
    xbee.begin(115200);
    xbee.reset();
    xbee.getWiResponse(MODEM_STATUS_RESPONSE, 5000); 

    xbee.setup(SECURITY_WPA2, "SSID", "PASSPHRASE");
      :
    data.setAddress(IpAddr(192, 168, 1, 2));
    data.setDstPort(1234);
    data.setSrcPort(5678);
    data.setProtocol(PROTOCOL_UDP);
    data.setPayload(buf);
    data.setPayloadLength(sizeof(buf));
    data.setFrameId(getNextFrameId());
    send(data);
      :
}

XBeeをAPIモードで使う (by Todotani) 電波強度(RSSI)の取得と、リモートのADC入力の実例

Import programXBeeApi_RemoteCommand

Sample program for XBee remote API operation. This program get ADC sample data from remote XBee connected over the radio

sample

#include "mbed.h"
#include "XBee.h"

XBee xbee(p13, p14); // 宣言

void main () {
    AtCommandResponse local = AtCommandResponse();
    RemoteAtCommandResponse remote = RemoteAtCommandResponse();
      :
    while (1) {
          :
        xbee.readPacket();
        if (xbee.getResponse().isAvailable()) {
            // XBeeより読み込み
            switch (xbee.getResponse().getApiId()) {
            case AT_COMMAND_RESPONSE:
                xbee.getResponse().getAtCommandResponse(local);
                if (local.getStatus() == AT_OK) {
                    // ローカルATコマンド、レスポンスの処理
                }
                break;
            case REMOTE_AT_COMMAND_RESPONSE:
                xbee.getResponse().getRemoteAtCommandResponse(remote);
                if (remote.getStatus() == AT_OK) {
                    // リモートATコマンド、レスポンスの処理
                }
                break;
            case ZB_RX_RESPONSE:
                xbee.getResponse().getZBRxResponse(rx);
                if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
                    // データパケット受信の処理
                }
              :
            }
        }
          :
    }
}

Original

XBee-mbed は XBee-Arduino ライブラリからの移植です。

through the serial mbed to xbee

mbed の PCシリアル=UART 経由で X-CTU による設定も可能。

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial xbee(p13, p14); // tx, rx

int main() {

    pc.printf("begin\r");

    for (;;) {
        if (pc.readable()) xbee.putc(pc.getc());
        if (xbee.readable()) pc.putc(xbee.getc());
    }
}

USB serial (mbed) <- -> P13, P14 (XBee)

mbeduino platform - mbed用マザーボード(ベースボード)

Can use the X-CTU.

Note

  • DNSサーバへリクエストを投げ返事が返ってきた瞬間にwifi接続が切れる。
    • XBee wifi → DNSリクエスト → DNS server (問題なし)
    • DNS server → DNSレスポンス → XBee wifi (wifi切断、UDPパケット受信しない)
    • しばらくするとwifi接続が回復する。
    • ポート53番以外であればこの現象は起こらない。
    • APIモードでもトランスペアレント(透過)モードでも同じく。
    • ファームウェアのアップデートで解決されることを期待。

Acknowledge

  • オリジナルからあったアナログ値取得の不具合修正(感謝 Ken Todotani

戻る (back)


02 Dec 2010
mbedでXBを使ってみたかったので非常に助かりました。
05 Dec 2010 . Edited: 05 Dec 2010

As it is issue of original Arduino library, I encountered the bug described in the following thread. For e.g,if you use AD3 disabling AD0-2, you don't get correct ADC value. So, I modified code in my local environments.

Problem with uint16_t ZBRxIoSampleResponse::getAnalog
07 Jan 2011
user Ken Todotani wrote:

As it is issue of original Arduino library, I encountered the bug described in the following thread. For e.g,if you use AD3 disabling AD0-2, you don't get correct ADC value. So, I modified code in my local environments.

Problem with uint16_t ZBRxIoSampleResponse::getAnalog

Thank you for your report.
I
changed this source.

5 comments on XBee-mbed library - XBee APIモードライブラリ:

20 Mar 2012

I'm getting the error:

identifier "LPC_UART" is undefined" in file "XBee/XBee.cpp", Line: 707, Col: 8

When I try to use your library with the mbed LPC11U24, what might I be doing wrong?

02 May 2012

こんにちは Mbedにコーディネーターをつなぎ、1つのエンドデバイスとの通信で、 API AT=2のモードで、ADCの値を読み込み表示することは出来ました。 2このエンドデバイスのADCを順番に読み込みたくいろいろやったのですができません。 2このエンドデバイスを順番に使うときの、remoteAddress のやり方を教えてもらえるとありがたいです。

11 Nov 2012

ありがとうございます、でもWhy don't you write it in English ? My Japanese is very bad..

01 Dec 2012

ありがとうございました!

You have made my day after many frustrating hours learning xbee. Now it is more fun!!!

17 Jul 2013

Hey Bro,

Thank you so much for the amazing work!

I've just started working with XBee. I'm trying to make it work in API mode but I'm having difficulties :( All I want to do right now is 1) to give command from one xbee(co-ordinator) which is connected with mbed to another xbee(Router) to send the status of Digital I/O pin 4 (such as the that pin is High or Low) & 2) Asking the xbee(Router) to give logic High or Low so I can light up a LED.

I already did the configuration of both xbee but now I'm stuck with mbed code :( I understand the Arduino code as it's very easily available everywhere & very widely used but I still haven't got that how to change that Arduino code to mbed using Xbee library. I tried to use your 1st sample code that deals with AD03

But unfortunately it doesn't give me High & Low on Digital I/O 3. It always gives 3.3V.

I also don't really know what the 3rd sample code does. .

I'm really sorry for the long message. But I really need some help asap. Everyone is telling me use Arduino but I want to stick with mbed. And according to you which platform is easier & better for xbee- mbed or Arduino? Can you give me a simple example that'll do what I'm looking for or any simple example of acquiring data or giving voltage through any specific AD pin? PLEASE HELP ME BRO!

Please log in to post comments.