많은 분들께 감사드립니다. Arduino 무선 센서 프로젝트를 시작하고 단서 벽을 쳤습니다. 모든 통찰력을 주셔서 감사 드리며 프로젝트의 문제를 해결하는 데 도움이됩니다.Arduino + wifi shield를 사용하여 Xively로 연결할 수 없습니다. "ret = -1 No sockets available"
저는 Arifino Mega를 사용하고 Wifi Shield를 사용하여 4 채널 (모든 수레)을 내 Xively 피드에 업로드하려고합니다. 기본 튜토리얼 스크립트 (하단의 코드)의 수정 된 양식을 사용하고 있습니다. 확인하고 성공적으로 업로드합니다. 게시판을 실행하면 초기 디버깅 정보가 잘 보입니다. put 또는 get 할 때 Xively 클라이언트 라이브러리를 사용하여 오류 (ret = -1, 사용 가능한 소켓 없음 및 HTTP 오류 가져옵니다). 오류의 일련 로그를 하단에도 첨부했습니다.
이미 몇 가지 문제 해결 단계를 수행했습니다. 나는 모든 xively 라이브러리와 Wifi 라이브러리를 다시 다운로드했습니다. 수동으로 DNS 서버 (8.8.8.8)를 설정하는 것이 도움이 될 것이라고 생각했습니다. 심지어 DNS 기능을 사용하려면 arduino 라이브러리 전체를 가져와야한다고 생각합니다. 차이를 만드는 것 같지 않아서 문제 해결 경로로 남겨 두었습니다. 또한 문제 해결 단계로, 당길 수 있지만 밀지 않을 수 있는지 확인하기 위해 Xively client.get 추가했습니다. HTTP 오류가 발생했습니다. 나는 또한 공개 프로젝트 공개 키를 내 프로젝트에 추가하고 그것을 시도했다. (개인적인 것 대신에). 아직도 기쁨이 없습니다.
내 Wi-Fi에 성공적으로 연결되어 있지만 실제로 어떤 서비스에도 연결할 수없는 것처럼 느껴질 수 있습니다. 내가 놓친 몇 가지 명백한 단계가 있었으면 좋겠다. 나는 정말로 올바른 길로 나를 데려 오기 위해 유용한 단서를 사용할 수 있습니다. 감사!
미가 Wyenn는
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
/*
Hot Tub Monitor
--- If you are only calibrating your sensor, use the calibrate sensor script. This is for submerged operation.
This script will allow you to test to ensure the temp, Ph, and ORD sensors are operating and are calibrated correctly.----
This script was written for the MEGA 2560 with the wireless shield, connecting in to Xively's cloud graph service
The Mega 2560 with the Wireless shield and Probes uses the following pins:
* SPI bus interface
* Onboard MicroSD card reader (uses SD Lib) on digital pin 4
* Digital Pins 7, 50, 51, 52, and 53 are reserved and shouldn't be used
* Digital Pin 18 is set to OUTPUT to power the temp probe on/off
* Atlas Scientific Temp Sensor input on Analog Uno pin A4
* Phidgets Ph Sensor input on Analog Uno pin A2
* Phidgets ORD Sensor input on Analog Uno pin A0
*/
// Libraries in use
#include <SPI.h>
#include <WiFi.h>
#include <b64.h>
#include <HttpClient.h>
#include <CountingStream.h>
#include <Xively.h>
#include <XivelyClient.h>
#include <XivelyDatastream.h>
#include <XivelyFeed.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
// setting up some of the globals
const int TEMPPIN = 4;
const int PHPIN = 1;
const int ORPPIN = 0;
boolean isDebugEnabled = true; //setting up the debug state
int status = WL_IDLE_STATUS;
char ssid[] = "<security snip>"; // your network SSID (name)
char pass[] = "<security snip>"; // your network password (use for WPA, or use as key for WEP)
// My Xively key to let you upload data
char xivelyKey[] = "<security snip>";
// My xively feed ID
#define xivelyFeed <security snip>
// My datastreams
char myWirelessStrStream[] = "MonitorWirelessStrength";
char myORPStream[] = "ORP";
char myPhStream[] = "Ph";
char myTempStream[] = "Temp";
// Creating the datastreams
XivelyDatastream datastreams[] = {
XivelyDatastream(myWirelessStrStream, strlen(myWirelessStrStream), DATASTREAM_FLOAT),
XivelyDatastream(myORPStream, strlen(myORPStream), DATASTREAM_FLOAT),
XivelyDatastream(myPhStream, strlen(myPhStream), DATASTREAM_FLOAT),
XivelyDatastream(myTempStream, strlen(myTempStream), DATASTREAM_FLOAT)
};
XivelyFeed feed(xivelyFeed, datastreams, 4);
//starting the Xively client
WiFiClient client;
XivelyClient xivelyclient(client);
void setup() {
if (isDebugEnabled) { //setting up the debug stream
Serial.begin(9600);
Serial.println("Hot Tub Monitor Debug Stream Starting");
Serial.println("-----------------------------------");
}
pinMode(12,OUTPUT); //this pin turns on the temp sensor - battery saver to have this on/off switchable
// connect to the wifi
// check for presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
//Connect to the wifi network
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("You're connected to the network");
Serial.println(status);
//printCurrentNet();
printWifiData();
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
}
void loop() {
// report on the WiFi Signal strength
long rssi = WiFi.RSSI();
if (isDebugEnabled) { //send the signal str to Xively
Serial.print("Sending RSSI to Xively: ");
Serial.println(rssi);
}
// print the received signal strength:
datastreams[0].setFloat(rssi);
// get the temp from our Atlas Sci probe
float tempC=get_temp();
float tempF = (tempC*1.8)+32;
datastreams[1].setFloat(tempF);
// debugging info for temp
if (isDebugEnabled) { //send the temp to Xively
Serial.print("Sending Temp to Xively: ");
Serial.println(tempF);
}
// get the Ph from our phidget's monitor
float Ph=get_Ph(tempC);
datastreams[2].setFloat(Ph);
// debugging info for Ph
if (isDebugEnabled) { //send the Ph to Xively
Serial.print("Sending Ph to Xively: ");
Serial.println(Ph);
}
// get the Ph from our phidget's monitor
float ORP=get_ORP();
datastreams[3].setFloat(ORP);
// debugging info for Ph
if (isDebugEnabled) { //send the Ph to Xively
Serial.print("Sending ORP to Xively: ");
Serial.println(ORP);
}
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
delay(10000);
}
float get_Ph(float tempC) {
float Ph = analogRead(PHPIN);
Ph = 7 -((2.5 - (Ph/200))/((0.257179 + 0.0000941468)*tempC)); // convert to the ph
return Ph;
}
float get_ORP() {
float ORP = analogRead(ORPPIN);
ORP = (2.5 - (ORP/200))/1.037; // convert to proper ORP
return ORP;
}
float get_temp(){
float v_out;
float Temp;
digitalWrite(A4, LOW); //wtf is this for?
digitalWrite(12, HIGH);
delay(2);
v_out = analogRead(4);
digitalWrite(12, LOW);
v_out*=.0048;
v_out*=1000;
Temp=0.0512 * v_out -20.5128;
return Temp;
}
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
}
-----------------------------Error Log Output------------------------------------------ Hot Tub Monitor Debug Stream Starting ----------------------------------- Attempting to connect to WPA SSID: LionsGate You're connected to the network 3 IP Address: 192.168.1.137 192.168.1.137 signal strength (RSSI):-27 Sending RSSI to Xively: -27 Sending Temp to Xively: 227.32 Sending Ph to Xively: 6.98 Sending ORP to Xively: 0.49 Uploading it to Xively xivelyclient.put returned -1 HTTP Error Sending RSSI to Xively: -27 Sending Temp to Xively: 154.33 Sending Ph to Xively: 6.94 Sending ORP to Xively: 0.87 Uploading it to Xively xivelyclient.put returned -1 HTTP Error Sending RSSI to Xively: -27 Sending Temp to Xively: 147.25 Sending Ph to Xively: 6.94 Sending ORP to Xively: 0.83 Uploading it to Xively No Socket available xivelyclient.put returned -1 No Socket available HTTP Error Sending RSSI to Xively: -27 Sending Temp to Xively: 149.91 Sending Ph to Xively: 6.94 Sending ORP to Xively: 0.87 Uploading it to Xively No Socket available xivelyclient.put returned -1 No Socket available HTTP Error