Ошибка HTTP при использовании Arduino WiFi Shield и Xively (WPA2)

Я только начал с Xively и попробовал базовое руководство ( https://xively.com/dev/tutorials/arduino_wi-fi/ ) Я только что изменил свой сетевой доступ на WPA2, который, кажется, работает, но затем я получаю следующий ответ в Serial Monitor:

Starting single datastream upload to Xively...

Attempting to connect to SSID: Tinker Lab
Connected to wifi
SSID: Tinker Lab
IP Address: 192.168.1.103
signal strength (RSSI):-45 dBm 

HTTP Error
Read sensor value 560.00
Uploading it to Xively
xivelyclient.put returned -1

Мой код выглядит следующим образом:

/*
##Xively WiFi Sensor Tutorial##
This sketch is designed to take sensors (from photocell) and upload the values to Xively
at consistant intervals. At the same time it gets a setable value from Xively to adjust the brigthness
of an LED. This sketch is reusable and can be adapted for use with many different sensors.
Derived from Xively Ardino Sensor Client by Sam Mulube.

By Calum Barnes 3-4-2013
BSD 3-Clause License - [http://opensource.org/licenses/BSD-3-Clause]
Copyright (c) 2013 Calum Barnes
*/
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>


char ssid[] = "Tinker Lab";     //  your network SSID (name) 
char pass[] = "passwordXXXX";  // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Your Xively key to let you upload data
char xivelyKey[] = "OAj0TV6KquAyLhQjR8T0dOxwzdm3ATl4ki9mWDXXXXXXXXX";  // just changed a few chars
//your xively feed ID
#define xivelyFeed 1763000000  // just changed a few numbers
//datastreams
char sensorID[] = "controller";
char ledID[] = "LED";

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
#define sensorPin A2
//led connected pin
#define ledPin 9

// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
  XivelyDatastream(ledID, strlen(ledID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);

WiFiClient client;
XivelyClient xivelyclient(client);

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm \n");
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pin setup
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);

  Serial.println("Starting single datastream upload to Xively...");
  Serial.println();

    // check for the presence of the shield:
   if (WiFi.status() == WL_NO_SHIELD) {
     Serial.println("WiFi shield not present"); 
     // don't continue:
     while(true);
   } 

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
     status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  //adjust LED level. set from Xively
  int getReturn = xivelyclient.get(feed, xivelyKey);    //get data from xively
  if(getReturn > 0){
    Serial.println("LED Datastream");
    Serial.println(feed[1]);
  }else Serial.println("HTTP Error");

  //write value to LED - change brightness
  int level = feed[1].getFloat();
  if(level < 0){
    level = 0;
  }else if(level > 255){
    level = 255;
  }
  //actually write the value
  digitalWrite(ledPin, level);

///////////////////////////////////////////////////////
  //read sensor values
  int sensorValue = analogRead(sensorPin);
  datastreams[0].setFloat(sensorValue);

  //print the sensor valye
  Serial.print("Read sensor value ");
  Serial.println(datastreams[0].getFloat());

  //send value to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  //return message
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);
  Serial.println("");


  //delay between calls
  delay(15000);
}

Я совершенно уверен, что это просто глупое начало...

Спасибо за помощь! Стефан


person user3271240    schedule 04.02.2014    source источник


Ответы (1)


Как вы получаете ошибку

HTTP-ошибка

это означает, что есть проблема с вызовом:

xivelyclient.get(feed, xivelyKey);

Следовательно, либо «канал», либо «xivelyKey» неверны.

Итак, сначала я бы дважды проверил правильность вашего ключа. Если все в порядке, проверьте правильность настроенного канала.

// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
  XivelyDatastream(ledID, strlen(ledID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);

Глядя на этот код, вам нужно убедиться, что вы правильно настроили ленту на сайте Xively; убедитесь, что «sensorID» действительно «контроллер», а «ledID» — «LED».

Те же наблюдения, которые я сделал, применимы к ошибке, возникающей при вызове:

int ret = xivelyclient.put(feed, xivelyKey);
person Ben Smith    schedule 04.02.2014
comment
Спасибо, Fresh, я удвоил и даже настроил новое устройство с новыми ключами и т. Д., Но проблема все еще та же :( Есть ли какой-то особый синтаксис, который я мог ошибиться? - person user3271240; 05.02.2014
comment
Я попробую запустить этот скетч-пример сегодня вечером, чтобы посмотреть, возникнет ли у меня та же проблема. - person Ben Smith; 05.02.2014
comment
ПОНЯТНО! Я прошил Arduino WiFi Shield последней прошивкой, и теперь он работает! - person user3271240; 06.02.2014
comment
Это отличные новости! Извините, что не ответил вам, вчера не было возможности разобраться. Это неприятная проблема, если его прошивка связана! - person Ben Smith; 06.02.2014