Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Arduino mega+;Gprs屏蔽sim 900_Arduino_Gprs_Xively - Fatal编程技术网

使用Arduino mega+;Gprs屏蔽sim 900

使用Arduino mega+;Gprs屏蔽sim 900,arduino,gprs,xively,Arduino,Gprs,Xively,我正在使用Arduino Mega2560和GPRS Shield Sim900,并尝试使用以下代码向Xively发送数据 要使用Sim900 GPRS Shield将数据发送到Xively,我应该对此代码进行哪些更改 /* * Xively WiFi Sensor Tutorial * * This sketch is designed to take sensors (from photocell) and * upload the values to Xively at consi

我正在使用Arduino Mega2560和GPRS Shield Sim900,并尝试使用以下代码向Xively发送数据

要使用Sim900 GPRS Shield将数据发送到Xively,我应该对此代码进行哪些更改

/*
 * 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[] = "SSID_HERE"; //  your network SSID (name) 
char pass[] = "PASS_HERE"; // your network password (use for WPA, or use as key for     WEP)
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[] = "API_KEY_HERE";
//your xively feed ID
#define xivelyFeed FEED_ID_HERE
//datastreams
char sensorID[] = "LIGHT_SENSOR_CHANNEL";
char ledID[] = "LED_CHANNEL";

// 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();

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, keyIndex, 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);
} 
/*
*XIVELLY无线传感器教程
*
*此草图设计用于获取传感器(来自光电管)和
*以一致的间隔将值上载到Xively。在
*同时,它从Xively获得一个可设置的值来调整
*发光二极管的亮度。此草图可重复使用,并且可以
*适用于多种不同的传感器。
*
*源自Sam Mulube的XIVELLY Ardino传感器客户端。
*
*由Calum Barnes于2013年3月4日撰写
*BSD 3条款许可证-[http://opensource.org/licenses/BSD-3-Clause]
*版权所有(c)2013 Calum Barnes
*/
#包括
#包括
#包括
#包括
char ssid[]=“ssid_在此”;//您的网络SSID(名称)
char pass[]=“在此处传递”//您的网络密码(用于WPA,或用作WEP的密钥)
int-keyIndex=0;//您的网络密钥索引号(仅WEP需要)
int状态=WL\U空闲\U状态;
//您的Xively密钥允许您上载数据
char xivelyKey[]=“API_KEY_HERE”;
//您的订阅源ID
#在此处定义xivelyFeed FEED_ID_
//数据流
char sensorID[]=“灯光传感器通道”;
char ledID[]=“LED_通道”;
//我们正在监控的模拟引脚(以太网屏蔽使用0和1)
#定义传感器引脚A2
//led连接引脚
#定义LED引脚9
//为数据流ID定义字符串
XIVELYDATASEAM数据流[]={
十四数据流(传感器ID、strlen(传感器ID)、数据流_浮点),
XivelyDatastream(ledID、strlen(ledID)、DATASTREAM_FLOAT),
};
//最后,将数据流包装到提要中
XivelyFeed提要(XivelyFeed,数据流,2/*数据流数量*/);
无线客户端;
XivelyClient XivelyClient(客户);
void printWifiStatus(){
//打印您连接到的网络的SSID:
序列号。打印(“SSID:”);
Serial.println(WiFi.SSID());
//打印您的WiFi屏蔽的IP地址:
ip地址ip=WiFi.localIP();
串行打印(“IP地址:”);
序列号println(ip);
//打印接收到的信号强度:
长rssi=WiFi.rssi();
串行打印(“信号强度(RSSI):”;
串行打印(rssi);
Serial.println(“dBm\n”);
}
无效设置(){
//将安装代码放在此处,以便运行一次:
Serial.begin(9600);
//引脚设置
引脚模式(传感器引脚,输入);
引脚模式(LED引脚,输出);
println(“开始将单个数据流上载到Xively…”);
Serial.println();
//尝试连接到Wifi网络:
当(状态!=WL_已连接){
Serial.print(“试图连接到SSID:”);
序列号println(ssid);
状态=WiFi.begin(ssid、keyIndex、pass);
//等待10秒钟以进行连接:
延迟(10 000);
} 
Serial.println(“连接到wifi”);
printWifiStatus();
}
void循环(){
//调整LED电平。从Xively开始设置
int getReturn=xivelyclient.get(feed,xivelyKey);//从xively获取数据
如果(getReturn>0){
Serial.println(“LED数据流”);
Serial.println(提要[1]);
}否则{
Serial.println(“HTTP错误”);
}
//将值写入LED-更改亮度
int level=feed[1].getFloat();
如果(级别<0){
级别=0;
}否则,如果(级别>255){
级别=255;
}
//实际写入值
数字写入(ledPin,电平);
//读取传感器值
int sensorValue=模拟读数(sensorPin);
数据流[0]。setFloat(传感器值);
//打印传感器值
串行打印(“读取传感器值”);
Serial.println(数据流[0].getFloat());
//将值发送给xively
Serial.println(“上传到Xively”);
int-ret=xivelyclient.put(feed,xivelyKey);
//回信
Serial.print(“xivelyclient.put返回”);
序列号println(ret);
Serial.println(“”);
//通话间隔
延迟(15 000);
} 

我应该使用其他库吗???要让这个SIM900防护罩工作起来相当困难,我还没听说有人能用上它。官方的Arduino/Telefonica屏蔽应该容易得多。SIM900对我来说非常有用。这个错误并不是因为SIM900模块有故障,我自己在汽车2G网络连接中使用过它,出于消费电子目的,请使用SIM900数据表中的内容检查AT命令