socket.error [error 146] connect refused | Arduino | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
socket.error [error 146] connect refused
Avatar
dyu
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
1
December 21, 2017 - 7:24 am
sp_Permalink sp_Print sp_EditHistory

I try to upload the values of humidity and temperature to thingspeak, but the something be wrong..

while the things.py (on Openwrt side) be executed, the result be showed as below.

root@mylinkit:~# python things.py
Traceback (most recent call last):
File "things.py", line 31, in <module>
p0 = value.get("PM2.5")
File "/usr/lib/python2.7/bridge/bridgeclient.py", line 76, in get
json = self.socket_open()
File "/usr/lib/python2.7/bridge/bridgeclient.py", line 59, in socket_open
self.json = TCPJSONClient('127.0.0.1', 5700)
File "/usr/lib/python2.7/bridge/tcp.py", line 65, in __init__
TCPClient.__init__(self, address, port)
File "/usr/lib/python2.7/bridge/tcp.py", line 38, in __init__
client.connect((address, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 146] Connection refused 

I do not know how to solve it, please help me, thank you so much.

 

Aurdino side..............................

// MCU To MPU
#include

// DHT
#include "DHT.h"
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
Bridge.begin();
}

void loop() {
// Get Temperature and Humidity
float h = dht.readHumidity();
float t = dht.readTemperature();

// Display Temperature and Humidity Value
Serial.print("DHT-Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("DHT-Temperature: ");
Serial.print(t);
Serial.println(" *C\t");

// MCU To MPU
Bridge.put("Humidity", String(h));
Bridge.put("Temperature", String(t));

delay(1000);
}

 

Openwrt side...............................things.py
import sys
import time
import httplib, urllib

sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
value = bridgeclient()
thinkSpeakApiKey = "PZ9BWVYAGTX3VUNU"

def post_to_thingspeak(payload):
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
not_connected = 1
while (not_connected):
try:
conn = httplib.HTTPConnection("api.thingspeak.com:80")
conn.connect()
not_connected = 0
except (httplib.HTTPException, socket.error) as ex:
print "Error: %s" % ex
time.sleep(10) # sleep 10 seconds

conn.request("POST", "/update", payload, headers)
response = conn.getresponse()
print( response.status, response.reason, payload, time.strftime("%c"))
data = response.read()
conn.close()

while True:
h0 = value.get("Humidity")
t0 = value.get("Temperature")
print "Humi: " + h0
print "Temp: " + t0
params = urllib.urlencode({'field1': t0, 'field2': h0, 'key': thinkSpeakApiKey})
post_to_thingspeak(params)
time.sleep(5)

Avatar
dyu
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
2
December 22, 2017 - 12:05 am
sp_Permalink sp_Print

I got the answer myself. Only with a sketch and python script is the bridge working. It can work.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

epicpaymentsny

DanielBobby

mercedeszw18

ujuxoketate

olihfez

winnieeq69

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee