-->
Page 1 of 1

RS 485 Data Logger using node MCU

PostPosted: Fri Jan 20, 2017 6:30 am
by Davinder Saini
hello All,

we are working on a project in which we have to acquire data from rs 485 port of energy meter and transmit it to our web server.

as of now we have successfully imported data from meter and post it to web server using http client.

now what we want is to store data of connectivity with server is lost and trasmit all the data as the conectivity goes up.

we got 200 as response after succesful hit. so this is our method to make sure that hit has been made successfully.

we want to make use of flash memory of node or we can use extenal card if required.

please suggest your ideas for coding.. here is my sample code.


#include <SDM.h> //import SDM template library

#define ASCII_ESC 27



#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;



char bufout[10];
float v,a,p,fre,pf,tu;
SDM<2400, 13, 12> sdm; //SDM120T baud, rx pin, tx pin
//SDM<4800, 12, 13> sdm; //SDM220T baud, rx pin, tx pin
//SDM<9600, 12, 13> sdm; //SDM630 baud, rx pin, tx pin
//or without parameters (default from SDM.h will be used):
//SDM<> sdm;

void setup() {
Serial.begin(115200);
USE_SERIAL.begin(115200);//initialize serial
USE_SERIAL.flush();
WiFiMulti.addAP("Spectrum", "silex@123");
sdm.begin(); //initalize SDM220 communication baudrate
}

void loop() {

//sprintf(bufout,"%c[1;0H",ASCII_ESC);
// Serial.print(bufout);

v=(sdm.readVal(SDM120C_VOLTAGE)); //display voltage
delay(10);
a=(sdm.readVal(SDM120C_CURRENT )); //display current
delay(10);
p=(sdm.readVal(SDM120C_POWER)); //display power
delay(10);
fre=(sdm.readVal(SDM120C_FREQUENCY )); //display frequency
delay(10);
pf=(sdm.readVal(SDM120C_POWER_FACTOR )); //display frequency
delay(10);
tu=(sdm.readVal(SDM120C_TOTAL_ACTIVE_ENERGY )); //display frequency

Serial.print("Volts:");Serial.println(v);
Serial.print("current:");Serial.println(a);
Serial.print("Power:");Serial.println(p);
Serial.print("Frequency:");Serial.println(fre);
Serial.print("Power factor:");Serial.println(pf);
Serial.print("Total Energy:");Serial.println(tu);
Serial.println(String("http://web*******.com/DataApp/GetValues.aspx?Value=") + String(v) + "," + String(a) + "," + String(p) +"," + String(fre) + "," + String(pf) +"," + String(tu)+"," + "dummy");
delay(5000); //wait a while before next loop


if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;
http.begin(String("http://web*********.com/DataApp/GetValues.aspx?Value=") + String(v) + "," + String(a) + "," + String(p) +"," + String(fre) + "," + String(pf) +"," + String(tu)+"," + "dummy");

int httpCode = http.GET();
http.end();
}
}

Re: RS 485 Data Logger using node MCU

PostPosted: Sat Apr 29, 2017 6:07 am
by manmoncang
can you share the cct diagram? tq

Re: RS 485 Data Logger using node MCU

PostPosted: Sat Apr 29, 2017 7:13 pm
by manmoncang
Dear @Davinder Sain 1st, may i get permission use your code above. TQ

2nd, I cannot get value from SDM120. Hopefully you can help. tq

Info:
    I use nodemcu.
    I connect RS485 to nodemcu as below:
  • RE tie with DE to pin D2 in nodemcu.
  • DI to Tx
  • RO to Rx

Dont why below code did not get any value from SDM120.

Code: Select all#include <SDM.h> //import SDM template library
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

//NODEMCU MAPPING PORT WITH ARDUINO
#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)

#define ASCII_ESC 27
#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

char bufout[10];
float v,a,p,fre,pf,tu;
SDM<2400, D9, D10> sdm; //SDM120T  baud, rx pin, tx pin
//SDM<4800, 12, 13> sdm; //SDM220T  baud, rx pin, tx pin
//SDM<9600, 12, 13> sdm; //SDM630 baud, rx pin, tx pin
//or without parameters (default from SDM.h will be used):
//SDM<> sdm;

//////////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(115200);
USE_SERIAL.begin(115200);//initialize serial
USE_SERIAL.flush();

 WiFiMulti.addAP("myssid", "mypass");
 while ((!(WiFi.status() == WL_CONNECTED))){
    delay(300);
    Serial.print("..");
  }
  Serial.println("Connected");
  Serial.println("Your IP is");
  Serial.println((WiFi.localIP()));

sdm.begin(); //initalize SDM120 communication baudrate

//SET PIN FOR RECEIVING DATA FROM RS485
pinMode(D2, OUTPUT);
digitalWrite(D2, LOW); //receiving = LOW; Sending = HIGH
}

//////////////////////////////////////////////////////////////////////////////
void loop() {

//sprintf(bufout,"%c[1;0H",ASCII_ESC);
// Serial.print(bufout);

v=(sdm.readVal(SDM120C_VOLTAGE)); //display voltage
delay(10);
a=(sdm.readVal(SDM120C_CURRENT)); //display current
delay(10);
p=(sdm.readVal(SDM120C_POWER)); //display power
delay(10);
fre=(sdm.readVal(SDM120C_FREQUENCY)); //display frequency
delay(10);
pf=(sdm.readVal(SDM120C_POWER_FACTOR)); //display frequency
delay(10);
tu=(sdm.readVal(SDM120C_TOTAL_ACTIVE_ENERGY)); //display frequency

Serial.print("Volts: ");Serial.println(v);
Serial.print("current: ");Serial.println(a);
Serial.print("Power: ");Serial.println(p);
Serial.print("Frequency: ");Serial.println(fre);
Serial.print("Power factor: ");Serial.println(pf);
Serial.print("Total Energy: ");Serial.println(tu);
delay(5000); //wait a while before next loop

}