无法通过Arduino wifi shield + Xively中继一个中继

时间:2015-03-27 12:38:56

标签: arduino wifi led xively iot

我正在尝试打开和关闭连接到Tinterkit继电器的LED灯泡。

由于官方的Arduino Wifi防护罩,我正在使用连接到互联网的Arduino UNO r3。

我做了一个简单的网站,有两个按钮可以向我的Xively帐户发送1(开启)或0(关闭)。

我编写了一个代码来检测最后发布的频道值。代码工作正常,我能够每3秒检测一次1或0。问题是继电器不通勤。

拜托,我非常感谢你帮助解决这个问题。

以下是代码:

#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>
#include <TinkerKit.h>

char ssid[] = "XXXXXX"; 
char pass[] = "XXXXXX";   

int state;
int status = WL_IDLE_STATUS;

char myIntStream[]="LED";
char xivelyKey[] = "XXXXXX";

#define FEED_ID XXXXXX

TKMosFet relay(O0); 

XivelyDatastream datastreams[] = {
  XivelyDatastream(myIntStream, strlen(myIntStream), DATASTREAM_INT),
};

XivelyFeed feed(FEED_ID,datastreams,1);

WiFiClient client;
XivelyClient xivelyclient(client);

void printWifiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void setup() {
  Serial.begin(9600);
  Serial.println("LED light bulb");
  Serial.println();

  while ( status != WL_CONNECTED) { 
    Serial.println("Connecting to internet ...");    
    status = WiFi.begin(ssid, pass);    
    Serial.println("");
    delay(5000);
  } 

  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  Serial.println();
  Serial.print("Datastream is:");
  Serial.println(datastreams[0]);

  Serial.print("LED value = ");
  state = datastreams[0].getInt();
  Serial.print(state);

  if(state == 0){    
    relay.off();  
    Serial.println(" => Light is on.");    
  }
  else if(state == 1){    
    relay.on();  
    Serial.println(" => Light is off.");      
  }
  xivelyclient.get(feed, xivelyKey);  
}

0 个答案:

没有答案