首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino在尝试使用Xively(Cosm)和Pusher时冻结

Arduino在尝试使用Xively(Cosm)和Pusher时冻结
EN

Stack Overflow用户
提问于 2013-05-30 22:20:30
回答 2查看 1K关注 0票数 0

我正在建造一个arduino供电的空调遥控器。我有实际的红外遥控触发器与pusher.com一起工作,但现在想要添加房间温度和空调单元的当前状态(开或关,从功率发光二极管读取使用光敏电阻)。

当我在草图中添加Xively代码并上传它时,arduino冻结了。我已经将其范围缩小到int ret = xivelyclient.put(feed,xivelyKey);它将调用来自xively库的put函数。如果您注释掉这一行,则pusher程序将照常运行。

如何让pusher和xively共存?它们是在争夺以太网屏上的连接吗?(我想我读到以太网屏可以同时处理4个连接)

代码如下:

代码语言:javascript
复制
#include <SPI.h>
#include <Ethernet.h>
#include <PusherClient.h>
#include <HttpClient.h>
#include <Xively.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };


PusherClient client;

 char xivelyKey[] = "myxivelykeyhere"; 
#define xivelyFeed 1454201282



int IRledPin =  8;    
int sensorPin = 0;



// Define the strings for our datastream IDs
char sensorId[] = "temp";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
XivelyFeed feed(15552, datastreams, 1 /* number of datastreams */);
EthernetClient Eclient;
XivelyClient xivelyclient(Eclient);



void setup() {
  pinMode(IRledPin,OUTPUT);



  Serial.begin(9600);

  Serial.println("I'm Alive");

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Init Ethernet failed");
    for(;;)
      ;
  }

  if(client.connect("336b1e021d66c95fad49")) {
    client.bind("togglePower", togglePower);

    client.subscribe("ac");
    Serial.println("Connected!");
  }
  else {
    while(1) {
    }
    Serial.println("Can't connect!!");
  }
}

void loop() {
  if (client.connected()) {
    client.monitor();
  }

  int reading = analogRead(sensorPin);  
  float voltage = reading * 5.0;
  voltage /= 1024.0; 
  float temperatureC = (voltage - 0.5) * 100 ;

 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");


  datastreams[0].setFloat(temperatureF);
   Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
//  Serial.println(ret);
  delay(8000);


}


void togglePower(String data) {
  Serial.println("togglePower() was triggered");  
  pulseIR(8860);
  delayMicroseconds(4360);
  pulseIR(600);
  delayMicroseconds(1580);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(480);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(480);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(580);
  delayMicroseconds(1600);
  pulseIR(600);
  delayMicroseconds(480);
  pulseIR(600);
  delayMicroseconds(1600);
  pulseIR(600);
  delayMicroseconds(1580);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(580);
  delayMicroseconds(520);
  pulseIR(580);
  delayMicroseconds(1600);
  pulseIR(600);
  delayMicroseconds(1580);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(1580);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(580);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(580);
  delayMicroseconds(500);
  pulseIR(600);
  delayMicroseconds(500);
  pulseIR(580);
  delayMicroseconds(1600);
  pulseIR(580);
  delayMicroseconds(520);
  pulseIR(580);
  delayMicroseconds(1600);
  pulseIR(600);
  delayMicroseconds(1600);
  pulseIR(520);
  delayMicroseconds(1660);
  pulseIR(520);
  delayMicroseconds(1660);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(580);
  delayMicroseconds(1600);
  pulseIR(520);
  delayMicroseconds(580);
  pulseIR(520);
  delayMicroseconds(41480);
  pulseIR(8840);
  delayMicroseconds(2200);
  pulseIR(540);
  delayMicroseconds(28564);
  pulseIR(8880);
  delayMicroseconds(2140);
  pulseIR(560);

}
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait

  cli();  // this turns off any background interrupts

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
    delayMicroseconds(10);         // hang out for 10 microseconds
    digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
    delayMicroseconds(10);         // hang out for 10 microseconds

    // so 26 microseconds altogether
    microsecs -= 26;
  }

  sei();  // this turns them back on
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-31 04:52:23

很可能你的Arduino内存用完了,你应该使用measure it

或者,您可以:

Arduino

  • 在不使用库的情况下将数据发送到(示例可以在Arduino IDE中找到

在文件-»Examples -»以太网-»(CosmClient、CosmClientString)下

这些都是相当过时的,但应该仍然可以正常工作,您可能想要替换为

  • 停止使用pusher,而只使用ws://api.xively.com:8080/,这将为您提供非常好的

频道或整个设备feeds的类似发布/订阅功能

第二种解决方案需要更多的工作和一个JSON解析器。但是,还有另一个选项to use MQTT,对于该选项,您可以使用Arduino IDE从1.0版开始附带PubSub库。与WebSoket端点不同,Xively的MQTT桥不需要JSON解析器,CSV数据格式可以与其一起使用。然后你就可以很容易地在JavaScript app中使用WebSocket了,除非你已经在Pusher alredy上实现了很多东西,否则我建议你只使用Xively/Arduino的MQTT。

如果你仍然遇到一些内存问题,你应该用你所包含的每个库的最基本的例子来测量使用情况。想要快速而简单的解决方案,你可以一直尝试使用Arduino Due,希望它也有更大的增长空间。

票数 1
EN

Stack Overflow用户

发布于 2013-06-28 06:14:00

您还应该考虑使用http://devicehub.net,他们现在有一个非常简单的HTTP api http://devicehub.net/about/api#api-guide,并且平台是开源的,而不是xively

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16838676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档