7731浏览
查看: 7731|回复: 11

[已解决] 买了块WiDo想与自建的WebAPI通信失败,求大神指点

[复制链接]
买了块WiDo想与自建的WebAPI通信失败,求大神指点
/***************************************************
* This is an example for the DFRobot WiDo - Wifi Integrated IoT lite sensor and control node
*
* Designed specifically to work with the DFRobot WiDo products:
*
*
* The main library is forked from Adafruit
*
* Written by Lauren
* BSD license, all text above must be included in any redistribution
*
****************************************************/
#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       "ChinaNet-Y2AT"           // cannot be longer than 32 characters!
#define WLAN_PASS       "lhzmkgww"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define TOKEN           "7daf"  //attach your own token generated from the DFRobot community website

// To get the full feature of CC3000 library from Adafruit, please comment the define command below
// #define CC3000_TINY_DRIVER    // saving the flash memory space for leonardo

#define TIMEOUT_MS      2000

void setup(){
  Serial.begin(115200);
  Serial.println(F("Hello, Wido!\n"));

  /* Initialise the module and test the hardware connection */
  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.
   */
  if (!WiDo.connectToAP(WLAN_SSID,WLAN_PASS,WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("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 IoTclient;

  if(IoTclient.connected()){
    //Convert LM35 sensor reading to degrees
    int sensValue = analogRead(0) *0.0048828125 * 100;

    char clientString[50];
    sprintf(clientString,"%s%s%s%s","GET  ","/Data?Value=",TOKEN," HTTP/1.1");
    Serial.println(clientString);

    // attach the token to the IOT Server and Upload the sensor dataIoTclient
    IoTclient.fastrprintln(clientString);

    IoTclient.fastrprint(F("\r\n"));
    IoTclient.fastrprint(F("\r\n"));

    Serial.println();
//    Serial.println("Upload data to the IoT Server");

    /* Read data until either the connection is closed, or the idle timeout is reached. */
    unsigned long lastRead = millis();
    while (IoTclient.connected() && (millis() - lastRead < TIMEOUT_MS)) {
      while (IoTclient.available()) {
        char c = IoTclient.read();
        Serial.print(c);
        lastRead = millis();
      }
    }
    IoTclient.close();
  }
  else{
    // Config the Host IP and DFRobot community IoT service port
    // Data Upload service PORT:  8124
    // Real time controling service PORT: 9120
    uint32_t ip = WiDo.IP2U32(211,149,219,61);
    IoTclient = WiDo.connectTCP(ip,8010);
    Serial.println("Connecting IoT Server...");
  }

  delay(5000);

}
买了块WiDo想与自建的WebAPI通信失败,求大神指点图1

请求的地址在浏览器中可以用 211.149.219.61:8010/api/data?value=eeeeeeuuuio


请大神们指点迷津。谢谢


Cain  初级技匠

发表于 2015-6-11 14:47:22

通信格式是什么?看反馈是完全没连上啊。先试试能否连上wifi,再试通信协议是否正确
回复

使用道具 举报

Ricky  NPC

发表于 2015-6-12 12:49:08

看反馈是你的服务器已经链接,有反馈数据,但是你的service并没有正确响应wido的request。建议自己看看webservice里的调用格式。
回复

使用道具 举报

Cain  初级技匠

发表于 2015-6-12 14:50:04

恩,说得对,“error400是请求出错
由于语法格式有误,服务器无法理解此请求。 不作修改,客户程序就无法重复此请求”
回复

使用道具 举报

maxfeel  见习技师
 楼主|

发表于 2015-6-18 07:48:36

感谢二位的答复,问题已经解决,问题出在get  传参数最后一个参数,实例代码给的默认是 HTTP/1.1,实际我服务器段用的是WebAPI,所以改成HTTPAPI/2.0 功能就实现了。但是目前测试感觉WidDo并不稳定,在单独加电(5V 1A)运行数个小时以后就停止工作。用USB接电脑串口监视,监视了一段时间串口也会停止接受数据。我个人感觉是硬件问题,想问问各位WIDO的稳定情况如何?????
回复

使用道具 举报

Cain  初级技匠

发表于 2015-6-18 09:35:04

可以试试降低波特率,加大通讯间隔等方式降低wido负载、避免通信口堵塞
回复

使用道具 举报

visionsl  初级技匠

发表于 2015-7-20 12:06:28

LZ的服务器段用的是WebAPI,是怎么看出来的?
回复

使用道具 举报

visionsl  初级技匠

发表于 2015-7-20 12:12:28

我测试了一下, 其实 " HTTP/1.1"可以完全去掉, 就可以正常工作了买了块WiDo想与自建的WebAPI通信失败,求大神指点图1

回复

使用道具 举报

yijian3014  学徒 来自手机

发表于 2015-10-13 17:23:39

说一句外行话,是不是他的自我工作机制?应该分辩一下是停止工作还是死机!
回复

使用道具 举报

yijian3014  学徒 来自手机

发表于 2015-10-13 17:24:39

停止工作是不是防止内存溢出?
回复

使用道具 举报

yijian3014  学徒 来自手机

发表于 2015-10-13 17:24:42

停止工作是不是防止内存溢出?
回复

使用道具 举报

yijian3014  学徒 来自手机

发表于 2015-10-13 17:24:43

停止工作是不是防止内存溢出?
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail