Sending Data from Blynk to another private server

Hello!

I am working on a project where i have to retrieve data from an RS485 module which is used to collect data from a sensor system with multiple probes attached to it. The data collected is in HEX format and will be converted to decimal and transferred on to BLYNK. I am using an ESP8266 working together with an Arduino Mega 2560 to connect to blynk. And i successfully managed to gather some of the data onto the BLYNK application to be viewed real time. I write this to inquire the possibilities of sending data to another platform (another web server). from Blynk itsel, and/or using the same setup with the same wired connection, there is a 2 wire serial Tx Rx connection with the esp8266 and the Arduino mega. The system has a common ground and is powered separately.
Attached here is an example sketch that i used to successfully obtain some of the sensor data on to the Blynk platform. Please be kind enough to help me send the same data which is going to blynk onto another online web-server, simultaneous to this.Thank you very much in advance.
Best!
Moh


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */


/**************************************************************************/
#define dirPin   4

const byte getPH[10] ={0x02,0x03,0x00,0xDB,0x00,0x02,0xB4,0x03};
//const byte getall[10]={0x02,0x03,0x00,0xDB,0x00,0x0C,0x35,0xF4};


unsigned long currentMillis,interval = 5000;
/**************************************************************************/
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

void myTemp()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, readTemp());
}

void myPH()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V7, readph());
}

void myDO1()
{
//  // You can send any value at any time.
//  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V8, readDO1());
}

void myDO2()
{
//  // You can send any value at any time.
//  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V9, readDO2());
}

void myCond()
{
//  // You can send any value at any time.
//  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V10, readCond());
}
void setup()
{

  pinMode(dirPin,OUTPUT);
  digitalWrite(dirPin,LOW);
  // Debug console
  Serial.begin(9600);
  Serial2.begin(9600);
  //Serial3.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(2000L, myTimerEvent);
  timer.setInterval(2000L, myTemp);
  timer.setInterval(2000L, myPH);
  timer.setInterval(2000L, myDO1);
  timer.setInterval(2000L, myDO2);
  timer.setInterval(2000L, myCond);

 // Serial.print("\r\npH Value =\t"); Serial.print(float(readPH()),3);
 // currentMillis = millis();

}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

/**************************************************************************/
float readTemp(void)
{

    
    int TempinHEX[9]={0};
    byte index=0;
    long fourByteHEX=0; 
    float Tempvalue=0;

    // SEND //
    digitalWrite(dirPin,HIGH);
    delay(10);
    Serial2.flush();
    //Serial2.write(" Data");
    Serial2.write((byte)0x01);
    Serial2.write((byte)0x03);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0xE5);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0x02);
    Serial2.write((byte)0xD5);
    Serial2.write((byte)0xFC);

    // TO Recieved //
    delay(10);
    digitalWrite(dirPin,LOW);

    index=0;
    while(Serial2.available()&&index<=9) {
    TempinHEX[index]=Serial2.read();
    index++;
    }

    Serial.print("\r\nData in HEX = \t");
    for(index=0;index<9;index++)
    {
       Serial.print(TempinHEX[index],HEX);
    }

    Serial.println();
  

  fourByteHEX = fourByteHEX | TempinHEX[5];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | TempinHEX[6];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | TempinHEX[3];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | TempinHEX[4];

  Tempvalue = convertToFloat(fourByteHEX);
  Serial2.flush();
  delay(50);
  return Tempvalue;
  
}



/**************************************************************************/
float readCond(void)
{

    
    int CondinHEX[9]={0};
    byte index=0;
    long fourByteHEX=0; 
    float Condvalue=0;

    // SEND //
    digitalWrite(dirPin,HIGH);
    delay(10);
    Serial2.flush();
    //Serial2.write(" Data");
    Serial2.write((byte)0x01);
    Serial2.write((byte)0x03);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0xE3);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0x02);
    Serial2.write((byte)0x35);
    Serial2.write((byte)0xFD);

    // TO Recieved //
    delay(10);
    digitalWrite(dirPin,LOW);

    index=0;
    while(Serial2.available()&&index<=9) {
    CondinHEX[index]=Serial2.read();
    index++;
    }

    Serial.print("\r\nData in HEX = \t");
    for(index=0;index<9;index++)
    {
       Serial.print(CondinHEX[index],HEX);
    }

    Serial.println();
  

  fourByteHEX = fourByteHEX | CondinHEX[5];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | CondinHEX[6];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | CondinHEX[3];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | CondinHEX[4];

  Condvalue = convertToFloat(fourByteHEX);
  Serial2.flush();
  delay(50);
  return Condvalue;
  
}
/**************************************************************************/
float readDO1(void)
{

    
    int DO1inHEX[9]={0};
    byte index=0;
    long fourByteHEX=0; 
    float DO1value=0;

    // SEND //
    digitalWrite(dirPin,HIGH);
    delay(10);
    Serial2.flush();
    //Serial2.write(" Data");
    Serial2.write((byte)0x01);
    Serial2.write((byte)0x03);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0xDF);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0x02);
    Serial2.write((byte)0xF5);
    Serial2.write((byte)0xF1);

    // TO Recieved //
    delay(10);
    digitalWrite(dirPin,LOW);

    index=0;
    while(Serial2.available()&&index<=9) {
    DO1inHEX[index]=Serial2.read();
    index++;
    }

    Serial.print("\r\nData in HEX = \t");
    for(index=0;index<9;index++)
    {
       Serial.print(DO1inHEX[index],HEX);
    }

    Serial.println();
  

  fourByteHEX = fourByteHEX | DO1inHEX[5];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO1inHEX[6];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO1inHEX[3];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO1inHEX[4];

  DO1value = convertToFloat(fourByteHEX);
  Serial2.flush();
  delay(50);
  return DO1value;
  
}


/**************************************************************************/
float readDO2(void)
{

    
    int DO2inHEX[9]={0};
    byte index=0;
    long fourByteHEX=0; 
    float DO2value=0;

    // SEND //
    digitalWrite(dirPin,HIGH);
    delay(10);
    Serial2.flush();
    //Serial2.write(" Data");
    Serial2.write((byte)0x01);
    Serial2.write((byte)0x03);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0xDF);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0x02);
    Serial2.write((byte)0xF5);
    Serial2.write((byte)0xF1);

    // TO Recieved //
    delay(10);
    digitalWrite(dirPin,LOW);

    index=0;
    while(Serial2.available()&&index<=9) {
    DO2inHEX[index]=Serial2.read();
    index++;
    }

    Serial.print("\r\nData in HEX = \t");
    for(index=0;index<9;index++)
    {
       Serial.print(DO2inHEX[index],HEX);
    }

    Serial.println();
  

  fourByteHEX = fourByteHEX | DO2inHEX[5];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO2inHEX[6];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO2inHEX[3];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | DO2inHEX[4];

  DO2value = convertToFloat(fourByteHEX);
  Serial2.flush();
  delay(50);
  return DO2value;
  
}
/**************************************************************************/

float readph(void)
{
    int pHinHEX[9]={0};
    byte index=0;
    long fourByteHEX=0; 
    float pHvalue=0;

    // SEND //
    digitalWrite(dirPin,HIGH);
    delay(10);
    //Serial2.write(" Data");
    Serial2.write((byte)0x01);
    Serial2.write((byte)0x03);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0xDB);
    Serial2.write((byte)0x00);
    Serial2.write((byte)0x02);
    Serial2.write((byte)0xB4);
    Serial2.write((byte)0x30);

    // TO Recieved //
    delay(10);
    digitalWrite(dirPin,LOW);

    index=0;
    while(Serial2.available()&&index<=9) {
    pHinHEX[index]=Serial2.read();
    index++;
    }

    Serial.print("\r\nData in HEX = \t");
    for(index=0;index<9;index++)
    {
       Serial.print(pHinHEX[index],HEX);
    }

    Serial.println();
  

  fourByteHEX = fourByteHEX | pHinHEX[5];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | pHinHEX[6];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | pHinHEX[3];
  fourByteHEX = fourByteHEX << 8;
  fourByteHEX = fourByteHEX | pHinHEX[4];
delay(50);
  pHvalue = convertToFloat(fourByteHEX);
  return pHvalue;
}

/**************************************************************************/
float convertToFloat(long Data)
{
  byte sign=0,exponent=0;
  unsigned long mantissa=0;
  float onlyFloatValue = 0;
  float returnFloat=0;
  
  exponent = ((Data & 0x7F800000) >> 23) - 127;
  mantissa = Data << 9 ;
  if(exponent>127){ returnFloat = 0.0; goto endConversion; }

  //Serial.print("\r\nexponent = \t"); Serial.print(exponent);
  //Serial.print("\r\nmantissa = \t"); Serial.print(mantissa);

  for(int q=1;q<24;q++)
  {
    if(mantissa & 0x80000000){ onlyFloatValue = onlyFloatValue + pow(2,-(q)); }
      mantissa = mantissa <<1;
  }

  //Serial.print("\r\onlyFloatValue = \t"); Serial.print(onlyFloatValue);

  onlyFloatValue = 1.0 + onlyFloatValue;

  returnFloat = float(pow(2,exponent)) * onlyFloatValue;
  //Serial.print("\r\return float = \t"); Serial.print(returnFloat);

  if(Data&0x80000000){ returnFloat = returnFloat * (-1); }
endConversion:
  return returnFloat;
  
}

If your ‘other platform’ has an API then you could use the Webhook widget to publish the data to it, or you could simply push your data from within the Arduino sketch.

Pete.

Hello Pete!

Thank you very much for your quick response. I did my research about webhook and it’s limitations. I will be recieving the details regarding the 3rd party service that i will be sending data via BLYNK early next week. I will update in the forums if i need help. Thank you again for your response.

Best!
Moh