WiDo WiFi物联网主控器

简介

Wido是一款轻量化WIFI传感器节点控制器,兼容Arduino Leonardo. 通过Wido你可以轻松对接国内外各大物联网平台,监控环境与设备数据。

产品参数

PS:4个Arduino Leonardo占用,MicroSD和CC3000都通过SPI驱动,固有硬件串口资源可扩展其他功能

应用

引脚图

Fig1: Wido Pin Out

**注意**:

如图所示,如果想驱动Wido自带的CC3000 WIFI功能需要占用扩展引脚上的3个数字口;

Wido 的主控为Leonardo,如果需要使用串口通信,请使用Serial1.\*\*\*()与相连的模块通信,Serial.\*\*\*()通过USB口与电脑通信。

新版本烧录教程

示例

实例一

在开始玩Wido接入各种传感器并向云服务或者网络传输数据前,我们先得将Wido连入本地的路由器或者中继。该样例会先帮助大家扫描附近已有的路由器信号,并配置Wido接入附近的路由器或者中继,Ping一个ip地址,同时了解Wido的一些基本功能。

硬件清单

软件工具

操作步骤

1.在以上链接下载CC3000 Arduino库并安装到Arduino库目录下(如何安装Arduino库

Fig2: Windows下库安装目录

2.从菜单栏,文件下样例程序中,Adafruit_CC3000分类中,打开buildtest.ino样例程序.

Fig3: 打开样例

3.在菜单栏工具中,选择Arduino Leonardo并选择正确的串口号,上传样例程序,并打开串口调试助手。看到如图。

Fig4: 扫描路由器

如图所示,Wido会在串口调试中打印出CC3000固件的版本,Wido模块的mac地址以及附近路由器的数量,SSID,信号强度以及加密类型。 4.更新您希望连入的路由器信息至程序中的以下内容:

//Please enter the SSID and password of the router you want to connect
#define WLAN_SSID       "myNetwork"        // cannot be longer than 32 characters!
#define WLAN_PASS       "myPassword"

5.在以上位置输入正确的SSID和路由器密码后重新上传样例程序,即可通过串口调试助手查看到,您的Wido已经接入网络并且能够ping到网络地址。

Fig5: Ping cn.bing.com

软件说明

通过以上操作步骤您的Wido已经能够正常连入您本地的路由器,并且与网络对接,包括访问网站,上传数据,建立TCP链接等等。 接下来我们简单地看下buildtest样例程序中几个主要用于建立网络连接的基础函数。

1.初始化Wido模块包括驱动引脚配置

  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }

2.根据设定的SSID、密码以及加密方式,连接本地路由器或者中继。

  /* NOTE: Secure connections are not available in 'Tiny' mode!
     By default connectToAP will retry indefinitely, however you can pass an
     optional maximum number of retries (greater than zero) as the fourth parameter.
  */
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

3.完成并获取DHCP动态地址分配信息

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

实例二

完成了网络连接后,下一步我们建立本地的TCP服务器数据对传,通过该教程您可以实现本地电脑和Wido的WIFI数据对传和实时控制。

软件工具

Tcp Server Tool - 用于在电脑端创建一个简单地TCP Server

操作步骤

1.打开Tcp服务器创建工具(USR-TCP232-Test),配置本地端口,点击Listening监听端口数据

Fig1: 创建TCP端口

2.打开Wido2LocalTcpServer样例程序 输入您本地路由器的SSID和密码配置Tcp服务器端口和IP配置,并上传程序到Wido

    /* Set the target ip address and connection port */
    uint32_t ip = WiDo.IP2U32(192,168,0,134);
    tcpClient = WiDo.connectTCP(ip, 4000);

样例代码


#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"

#define WiDo_IRQ   7
#define WiDo_VBAT  5
#define WiDo_CS    10
Adafruit_CC3000 WiDo = Adafruit_CC3000(WiDo_CS, WiDo_IRQ, WiDo_VBAT,
                                         SPI_CLOCK_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "myNetwork"           // cannot be longer than 32 characters!
#define WLAN_PASS       "myPassword"

// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2
#define TIMEOUT_MS  1000

void setup(){

  Serial.begin(115200);
  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!WiDo.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }

  /* NOTE: Secure connections are not available in 'Tiny' mode!
     By default connectToAP will retry indefinitely, however you can pass an
     optional maximum number of retries (greater than zero) as the fourth parameter.
  */

  Serial.println(F("Connecting Router/AP"));
  if (!WiDo.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("Router/AP Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!WiDo.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }
}

void loop(){

  static Adafruit_CC3000_Client tcpClient;
  static unsigned long heartRate = millis();

  if(!tcpClient.connected()){
    Serial.println("Try to connect the Local Server");
    tcpClient.close();

    /* Set the target ip address and connection port */
    uint32_t ip = WiDo.IP2U32(192,168,0,134);
    tcpClient = WiDo.connectTCP(ip, 4000);

    if(!tcpClient.connected()){
      Serial.println(F("Couldn't connect to server! Make sure TCP Test Tool is running on the server."));
      while(1);
    }
  }
  else if(millis() - heartRate > 1000){
    heartRate = millis();  // Update time stamp of the microcontroller system

    char clientString[30];
    sprintf(clientString, "%s%d%s", "Wido heartRate: ",heartRate/1000," s\r\n");

    Serial.println(clientString);
    tcpClient.fastrprintln(clientString);
  }

  /* Read data until either the connection is closed, or the timeout is reached. */
  unsigned long lastRead = millis();
  while (tcpClient.connected() && (millis() - lastRead < TIMEOUT_MS)) {
    while (tcpClient.available()) {
      char c = tcpClient.read();
      Serial.print(c);
      lastRead = millis();

      // Disable sending message for a moment
      heartRate = millis();
    }
  }
}

结果

成功了上传程序后,打开串口调试助手即可看到,Tcp Server能够接收到Wido发送的心跳信息。通过Tcp也能向Wido创建的Client发送反馈数据

Fig2: 查看效果

疑难解答

更多问题及有趣的应用,可以访问论坛进行查阅或发帖!

更多

应用教程:使用wido上传数据到machtalk物联网平台2018

DFshopping_car1.png DFRobot商城购买链接