Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Unable to push data from arduino to emoncms on raspberry pi

Hi I am struggling with pushing data from arduino to emoncms which I have installed on raspberry pi. Can you help me out regarding this?

Code on Arduino IDE is

#include <DHT.h>
#include <DHT_U.h>

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN 2     // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

const int nodeID = 6;

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(38400);
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(nodeID);     Serial.print(' ');
  Serial.print(h);Serial.println(' ');

  delay(1000);

}

How are the two physically connected?

Mine works without NodeID. Also my printlin() has nothing inside. Try this:
Serial.print(h); Serial.print(’ ');
Serial.println();

[[SerialDirect]]
Type = EmonHubSerialInterfacer
[[[init_settings]]]
com_port = /dev/ttyAMA0
com_baud = 115200 // or 38400
[[[runtimesettings]]]
pubchannels = ToEmonCMS,
nodeoffset = 8

[[8]]
nodename = emontx3
[[[rx]]]
names = temp1
datacode = 0
scales = 1
units =C

1 Like

Through direct USB port of r-pi arduino i connected

Hi Man, still after the changes it shows this

How to get rid of this n/a

Please do not double post. Double posting creates two possible sets of replies and confuses everyone.
The duplicate post has been deleted.

Thank you,

Moderator

1 Like

If you are not using a standard approach, you can not really expect it to happen by magic.

Did you edit the emonhub config?

Please post the emonhub config file.

Next look at the emonhub logs. Is it reading the data correctly?

A while back, I remember that I wasn’t able to get the USB Serial to work, so I used the UART Hardware serial of the Raspberry PI. You will have to use a 3.3V/5V level-shifter to protect the Raspberry Pi when connecting RX and TX to a 5vdc Arduino.

Hi,

Following are my emonhub config file and emonhub log. Can you kindly give it a look? As I am confused about datacode as it is giving an error “RX data length: 1 is not valid for datacodes 1” as can be seen in emonhub log file.

emonhubconf.txt (7.9 KB) emonhublogs.txt (2.6 KB)

Try commenting out the datacodes = 1 or edit it to datacodes = 0. Since you are passing a float value no decoding is necessary.

What about integer value data

While the data you send is a string of text, “123” or “123.456”, the same applies.

1 Like

I am stuck! Unable to get data on local emoncms. FIles emonhub and emonhub logs already shared. What could be the reason I am not using any shield simply have connected arduino with raspberry pi. Any help please?

If you connect to the serial port with miniterm what data are you seeing?