Can't refresh sensors

3 years 8 months ago #3136 by NightOne
What do you see when you connect to the arduino serial..... Do this to make sure that the DHT is reading Values....

You should see:

Temperature: (then some value)
Humidity: (then some value).

If DHT is not working these will be blank.

You can "force" you code to make sure its reading the DHT sensor by adding the following:

In your void loop

do {
t = dht.readTemperature();
h = dht.readHumidity();
Serial.print("Temperature: ");
Serial.print("Humidity: ");
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
} while (t == 85.0 || t == (-127.0));

The 2000 delay at the beginning is more for the cheaper DHT11 sensor as the sensor needs time to stabalise before the read....but leaving it in for the DHT22 wont hurt.

Please Log in or Create an account to join the conversation.

3 years 8 months ago #3138 by Adamyno
Yes, DHT works. I will see with Wireshark, what happening on the network. I think, my ethernet module is not reliable becouse when I leave it with Dallas temperature sensor, after some minutes or hours it doesnt works. Tomorrow I will have a Raspberry Pi, maybe it will be more reliable the server also. ( that doesn't run any other programs like my win ). So.. lets see what happens :)

Please Log in or Create an account to join the conversation.

3 years 8 months ago #3139 by Adamyno
I found something. The source code has many strings, what uses more RAM. I use F("String") method to transmit static strings to Flash. Before I had 72% used of RAM, after now it is only 63%, so the remaining is free for variables. It is true for Dallas Temp sensor.

With DHT22 I used the same procedure, and the used RAM is 62%. Now it works, but after some minutes the ethernet POST messaging stops. I don't know why. I think that may be due to memory fragmentation. I will try with an Arduino Mega,
I am curious what will happen.

Please Log in or Create an account to join the conversation.

3 years 8 months ago #3140 by Adamyno
I know what was the problem.
Now I use Uno and Ethernet Shield. I have more more free RAM and it works correctly. The problem is the UIPEthernet library or the ENC28J60 module. In the future I will detect that. Problem solved, but I don't know what is the problem with ENC28J60. There are another librarie(s), I will try.

Please Log in or Create an account to join the conversation.

3 years 8 months ago - 3 years 8 months ago #3141 by NightOne
I see a lot of people on the internet have the same problem with ENC28J60 freezing or stop working over time....
What you can try is to get it to disconnect from the network while it is not updating.... something like ethernet,stop()
I have this on my ESP8266 but that is more to save power.....
When you want to post temp and humidity just call lanconnect again and then drop the connection afterwards with ethernet.stop()

You can also try this library:
The following user(s) said Thank You: Adamyno

Please Log in or Create an account to join the conversation.

3 years 8 months ago #3155 by Adamyno
The problem solved. I'm using Arduino 1.6.7, UIPEthernet by ntruchsess V1.50.0.
Using client.stop(); solves the problem.

Here is the good, working source:
#include <UIPEthernet.h>
#include <SPI.h>
#include <Base64.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define EIOT_USERNAME F("admin")
#define EIOT_PASSWORD F("test")
#define EIOT_IP_ADDRESS ""
#define EIOT_PORT 8080
#define EIOT_NODE F("N20S0")

#define REPORT_INTERVAL 60 // in sec

#define ONE_WIRE_BUS 6 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS); //DallasTemperature DS18B20(&oneWire);
DallasTemperature sensors(&oneWire);

#define USER_PWD_LEN 40
char unameenc[USER_PWD_LEN];
float temp;
float oldTemp;
byte s = 5;

byte mac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
IPAddress ip(192, 168, 1, 170);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

void setup() {

  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME) + ":" + String(EIOT_PASSWORD);
  str.toCharArray(uname, USER_PWD_LEN);
  memset(unameenc, 0, sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
  oldTemp = -1;

void loop() {
  do {  
    temp = sensors.getTempCByIndex(0);
    Serial.print(F("Temperature: "));
  } while (temp == 85.0 || temp == (-127.0));

  if (temp != oldTemp)
    oldTemp = temp;

  int cnt = REPORT_INTERVAL;

  while (cnt--)

void lanConnect()
  EthernetClient client;
  Ethernet.begin(mac, ip, myDns, gateway, subnet); {

  Serial.println(F("Lan connected"));

void sendTeperature(float temp)
  EthernetClient client;
  while (!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println(F("connection failed"));

  String url = "";
  url += "/Api/EasyIoT/Control/Module/Virtual/" + String(EIOT_NODE) + "/ControlLevel/" + String(temp); // generate EasIoT server node URL

  Serial.print(F("POST data to URL: "));

  client.print(String(F("POST ")) + url + F(" HTTP/1.1\r\n") +
               F("Host: ") + String(EIOT_IP_ADDRESS) + "\r\n" +
               F("Connection: close\r\n") +
               F("Authorization: Basic ") + unameenc + " \r\n" +
               F("Content-Length: 0\r\n") +

  while (client.available()) {
    String line = client.readStringUntil('\r');

  Serial.println(F("Connection closed"));

Please Log in or Create an account to join the conversation.

Time to create page: 0.213 seconds

Forum latest

  • No posts to display.