0

我正在尝试使用 zigbee 协议,在两辆车之间建立通信,作为 VANET 中车辆间通信的一部分。所以,由于我对此很陌生,我想知道:

一个。我是否必须对我的 Zigbee 接口进行编程才能建立通信?湾。是否可以对 zigbee 接口进行编程?C。谁能给我一个关于如何在两个 zigbee 之间建立(使用编程语言)通信的一般概念。?

任何帮助,将不胜感激。

4

1 回答 1

0

一个。要建立连接并进行简单的发送/接收数据(在 2 个接口/模块之间),您无需对 ZigBee 接口(例如 XBee)进行编程。只需使用 XCTU 配置它们。但是,如果你想让它们按照你喜欢的方式相互交流(使用你自己的规则),你必须对它们进行编程。

湾。如果你有 XBee 模块,那么你可以使用基于 Java 的xbee-api 。对于其他模块,请查看您模块的文档。

C。此示例取自使用 Java 编程语言的xbee-api网页(示例代码)。这段代码所做的是搜索所有附近的模块(节点发现):

/**
 * Copyright (c) 2008 Andrew Rapp. All rights reserved.
 *  
 * This file is part of XBee-API.
 *  
 * XBee-API is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * XBee-API is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with XBee-API.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rapplogic.xbee.examples.zigbee;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.AtCommand;
import com.rapplogic.xbee.api.AtCommandResponse;
import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.zigbee.ZBNodeDiscover;
import com.rapplogic.xbee.util.ByteUtils;

/**
 * Example of performing a node discover for Series 2 XBees.
 * You must connect to the coordinator to run this example and
 * have one or more end device/routers that are associated.
 *
 * @author andrew
 *
 */
public class ZBNodeDiscoverExample {

        private final static Logger log = Logger.getLogger(ZBNodeDiscoverExample.class);

        private XBee xbee = new XBee();

        public ZBNodeDiscoverExample() throws XBeeException, InterruptedException {

                try {
                        // replace with your serial port
                        xbee.open("/dev/tty.usbserial-A6005v5M", 9600);


                        // get the Node discovery timeout
                        xbee.sendAsynchronous(new AtCommand("NT"));
                        AtCommandResponse nodeTimeout = (AtCommandResponse) xbee.getResponse();

                        // default is 6 seconds
                        int nodeDiscoveryTimeout = ByteUtils.convertMultiByteToInt(nodeTimeout.getValue()) * 100;                      
                        log.info("Node discovery timeout is " + nodeDiscoveryTimeout + " milliseconds");

                        log.info("Sending Node Discover command");
                        xbee.sendAsynchronous(new AtCommand("ND"));

                        // NOTE: increase NT if you are not seeing all your nodes reported

                        List<? extends XBeeResponse> responses = xbee.collectResponses(nodeDiscoveryTimeout);

                        log.info("Time is up!  You should have heard back from all nodes by now.  If not make sure all nodes are associated and/or try increasing the node timeout (NT)");

                        for (XBeeResponse response : responses) {
                                if (response instanceof AtCommandResponse) {
                                        AtCommandResponse atResponse = (AtCommandResponse) response;

                                        if (atResponse.getCommand().equals("ND") && atResponse.getValue() != null && atResponse.getValue().length > 0) {
                                                ZBNodeDiscover nd = ZBNodeDiscover.parse((AtCommandResponse)response);
                                                log.info("Node Discover is " + nd);                                                    
                                        }
                                }
                        }
                } finally {
                        xbee.close();
                }
        }

        public static void main(String[] args) throws XBeeException, InterruptedException {
                PropertyConfigurator.configure("log4j.properties");
                new ZBNodeDiscoverExample();
        }
}
于 2013-12-09T06:38:53.763 回答