-->
Page 1 of 2

Sending DATA from ESP8266 to WebServer + via ArduinoIDE

PostPosted: Tue Oct 06, 2015 3:53 am
by babsndeep
Hello Everyone!

I'll begin by saying that this community is awesome :) providing wonderful and insightful information to noobs such as myself. Please bare with me as this is a long post.

GOAL: Send Data from an attached sensor to the ESP8266-01 to a WebServer and store that information in a mySQL DB running on the WebServer. I wanted to do everything from scratch, So I went ahead and half-assed my way through setting up a simple WebServer on my Laptop using WAMP (actually still in the process of finishing, I'll come back to this later).

PROGRESS: I have downloaded Arduino IDE support for ESP8266 and uploaded the following code on the ESP8266-01:
***********************************************************************************************
#include <ESP8266WiFi.h>

const char* ssid = "ssid";
const char* password = "password";


void setup(){
Serial.begin(115200);
delay(10);

WiFi.begin(ssid,password);

while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.println(".");
Serial.println("Connected to ");
Serial.println(ssid);
}
}

void loop(){
Serial.println("Hello, Internet");
delay(1000);
Serial.println("IP Address");
Serial.println(WiFi.localIP());
delay(2000);
}
***********************************************************************************************
With the above code running on the ESP8266-01 I am able to have the Chip connect to my SSID on bootup (I was also able to attach a Sensor to GPIO2 for collecting Analog Data, but kept the code out for simplification)

NEED HELP: Now we come to the reason why I've been pulling my hair for the past few weeks, Not knowing any HTML,PHP or Web programming I was able to understand the basics and created a simple Webpage, However I wasn't able to setup a mySQL DB where the incoming Data from ESP8266 will be stored, and nor have I any clue as to how to get he ESP8266 to SEND Data to the WebServer.

TO SUMMARIZE: PLEASE HELP WITH THE FOLLWOING
1) Sample code that allows the ESP8266 to SEND Data to a Webserver
2) Documentaiton/Guide for setting up a WebServer using WAMP and accepting the incoming Data from the ESP8266 and store that Data in a mySQL DB.

Would appreciate Help of any Sort. Be it Documentation/Videos/Tutorials/Guides etc.

Thanks Again for taking the time to Help.
Best

Re: Sending DATA from ESP8266 to WebServer + via ArduinoIDE

PostPosted: Tue Oct 06, 2015 3:34 pm
by eduperez
First you have to do #2, and that is well beyond the scope of this forum, in my humble opinion; a quick search for "XAMPP tutorial" yields several promising results:

http://www.phpknowhow.com/
http://html.net/tutorials/php/
https://jadendreamer.wordpress.com/2011 ... e-hosting/

Once you have #1 done, you will have a URL that can send data to your server, and the rest is a piece of cake.

Re: Sending DATA from ESP8266 to WebServer + via ArduinoIDE

PostPosted: Tue Oct 06, 2015 4:10 pm
by xtal
I have no Arduino and don't know C
I've attached my LUA which uses POST and contains some HTML code
Maybe this will be of some help
I do get not enough memory then must reset then dofile to run...under nodemcu...

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("12345NETGEAR","mikeis12345")

tmr.alarm(0, 1000, 1, function(QQ)   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)
rfctr=0
adc_id = 0
adc_value = 512
k1=0.11
p00='P'
apc0='11111'
ppm0='1770'
cdeg0='25.1'

kta0='0.01'
lo0='12'
hi0='20'
prb='01.0'
ph='7.0'
sbuf=""
Eopn=0
B_Opn = "http://i.imgur.com/kzt3tO8.png"
B_Clo = "http://i.imgur.com/KS1dPa7.png"
bgc="Cyan"
s_img = B_Opn
-- simple uart input appears to work
 uart.setup(0,9600,8,0,1)
srv = net.createServer(net.TCP, 30)
srv:listen(80,function(C)
     C:on("receive", function(C, payload)               
          function esp_update() 
  --print("--PL--",payload)
                     
            m_do=string.sub(payload,postparse[2]+1,#payload)
            x=string.find(m_do,"&m_do=")
         
            if x ~= nil then
               cmd=string.sub(m_do,x+6,#m_do)
               m_do=string.sub(m_do,1,x-1)
            else               
               cmd=string.sub(m_do,1,#m_do)
               m_do=nil
            end
               
            cmd=string.gsub(cmd,"+","")         -- remove lead/trail +       
      --  print("m_do-2 ",m_do,"  cmd "..cmd)
           
           if cmd ~= nil then
  print("---",cmd)           
             uart.write(0,cmd.."\n\r")          -- send to PIC
        --     print("-->uart-->pic=|"..cmd.."\n\r")           
           end
                             
            if m_do == "RD_ADC" then
               adc_value = adc.read(adc_id)
                    if adc_value > 1023 then
                         adc_value = 1023
                    elseif adc_value < 0 then
                         adc_value = 0
                    end                                 
            end
           
            if m_do == "BLINK" then
               if Eopn==0 then
                  s_img =B_Clo
                  Eopn=1
                bgc="Yellow"
               else
                  s_img =B_Opn
                  Eopn=0
               bgc="Cyan"
              end
            end             
            if m_do == "TEMP_DN" then
                apc0 = apc0 + 100
                cdeg0=round2((cdeg0-1),1)                           
            end   
            if m_do == "TEMP_UP" then 
                apc0 = apc0 - 100         
                cdeg0=round2((cdeg0+1),1)                           
            end           
        end     
        postparse={string.find(payload,"m_do=")}
        if postparse[2]~=nil then esp_update()end
      --C:send('HTTP/1.1 200 OK\n\n')
fdeg0 = round2((cdeg0*1.8) +32,1)
ppm1=round2(ppm0/(((cdeg0-25)*.021)+1),1)
ppm2=round2((ppm0*46.5)/(cdeg0+21.5),1 )
pha=25-cdeg0
if pha < 0 then
   pha = round2((ph + (pha*.002)),2)
else
   pha = round2((ph + (pha*.004)),2)   
end
rfh='15'   
C:send('<!DOCTYPE HTML>\n<html lang="en-US">\n<head><meta http-equiv="refresh" content="'..rfh..'" ></head>\n')
C:send('<script type = "text/javascript">\nvar timeInSecs;\nvar ticker;')
C:send('function startTimer(secs){ timeInSecs = parseInt(secs)-1; ticker = setInterval("tick()",1000); }')
C:send('function tick() { var secs = timeInSecs; if (secs>0) {timeInSecs--;} else {clearInterval(ticker); startTimer('..rfh..');}')               
C:send('document.getElementById("countdown").innerHTML = secs;} startTimer('..rfh..'); </script>')
C:send('<body><div><table bgcolor="Lawngreen" border="1" cellpadding="5"><th><h1>ESP8266 Blinker Thing!</h1></th><td>'
..'<IMG SRC="'..s_img..'" LEFT="1" WIDTH="120" HEIGHT="60" BORDER="1"></td><th id="countdown">'..rfh..'</th></table><div><br>')
C:send('<textarea name="cmds" cols="70" rows="14">'..sbuf..'</textarea></div><br>')
C:send('<textarea name="cmds" cols="70" rows="6">'..sbuf..'</textarea></div><br>')   
C:send('<div><table bgcolor="'..bgc..'" border="1" cellpadding="5">')
C:send('<tr><th>Sensor</th><th>TempC</th><th>TempF</th><th>PPMcntr</th><th>PPM__</th><th>Adj__1</th><th>Adj__2</th></tr>')
C:send('<tr><td>DS18B20'..p00..'</td><td>'..cdeg0..'</td><td>'..fdeg0..'</td><td>'..apc0..'</td><td>'..ppm0..'</td><td>'..ppm1..'</td><td>'..ppm2..'</td></tr>')
C:send('<tr><th>Probe-K</th><th>Pool-PH</th><th>PH-Adj</th><th>ADC Value</th></tr>')     
C:send('<tr><td>'..prb..'</td><td>'..ph..'</td><td>'..pha..'</td><td bgcolor="Red">'..adc_value..'</td></tr>')       
C:send('</table></div><br><form action="" method="POST">\n')
C:send('<input type="submit" name="m_do" value="BLINK" style="padding:5px;10px;">')
C:send('<input type="submit" name="m_do" value="RD_ADC" style="padding:5px;10px;">')     
C:send('<input type="submit" name="m_do" value="TEMP_DN" style="padding:5px;10px;">')
C:send('<input type="submit" name="m_do" value="TEMP_UP" style="padding:5px;10px;"><br>')                   
C:send('"CMD:"<input type="text" name="m_do" value="" maxlength="100" style="padding:5px;10px;">')
C:send('<input type="submit" value="Submit"></form>\n<br></body></html>\n')     
C:on("sent", function(C) C:close() end)
       
     end)
 
rfctr=(rfctr+1) 
rfc=math.floor((rfctr/2)+0.5)  -- seems to double count so /2 and round
if (rfc % 2)==0 then
   bgc="Cyan"    --even
else
    bgc="Yellow" --odd
end   
             
end)
function round2(num, idp)
  return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function si(sIN)   
   buffer=sIN
 
if string.find(sIN,"=si('") then
   sa=string.find(sIN,"=si('I")
   sb=string.find(sIN,"')")
   sbuf=sbuf..string.sub(sIN,sa+6,sb)
end
     
      -- print("\n\rbuf--",buffer)
      if string.find(sIN,"co") then
      if string.find(sIN,"bo") then             
      cx=(string.find(sIN,"co"))+2
      cdeg0 = string.sub(sIN,cx,cx+3)         
       if string.find(sIN,"ao") then
       cx=(string.find(sIN,"bo"))+2             
       ppm0=string.sub(sIN,cx,cx+3)                               
        if string.find(sIN,"xo") then
        cx=(string.find(sIN,"ao"))+2
        apc0 = string.sub(sIN,cx,cx+4)
        end
       end   
      end
      end       
end
function cbuf()
  if #sbuf + #sIN > 200 then
     sbuf = sIN
  else
     sbuf = sbuf..sIN
  end
end               
function all_trm(s)
   return s:match( "^%s*(.-)%s*$" )
end   
function all_trim(s)
  return s:match"^%s*(.*)":match"(.-)%s*$"
end     
 

Re: Sending DATA from ESP8266 to WebServer + via ArduinoIDE

PostPosted: Wed Oct 07, 2015 2:20 am
by fixduino
hello. nice to know ESP8266. i am still study about esp07.
and Just for information, and get more information for use ESP8266, i will sharing the sketch of my experience for sending data to server (localhost).

i have sending data temperature,and other data in the field via router. in this case i use XBoard (arduino with ethernet shield), sensor ds18b20.in PC server i am use XAmpp.


this is the listing code.
Code: Select all
 /*
   sistem monitoring level kolam pemadam via website
   Posted January 16 by fixduino
   Last modified juni 12, 2014
   
   +suhu pmk1 dan pmk2
   +justifikasi Tkolam dilapangan
   +ediit pageadd/outbuf 256
   + with median methode
   ++ plus alarm, new table
   ++with maxsonar
   ++ volume updated
   
   --ping average level done
   --localhost done
   
*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//start of define IPaddress for LAN connection
// this must be unique code for arduino
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// change to your network settings
IPAddress ip(192,168,1,10);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
// change to your server
IPAddress server(192,168,1,15);  //192,168,1,2
//Change to your domain name for virtual servers
char serverName[] = "localhost";
// change to your server's port
int serverPort = 80;
EthernetClient client;
//end of define LAN connection

//#start of define sensor suhu
#define ONE_WIRE_BUS_PIN 2
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
//address of each sensor
DeviceAddress Probe01 = { 0x28, 0x80, 0xF9, 0x2D, 0x06, 0x00, 0x00, 0x9D }; //TPMK1
DeviceAddress Probe02 = { 0x28, 0xB9, 0xF1, 0x2C, 0x06, 0x00, 0x00, 0x57 }; //TPMK2
//parameter temp which will found
float tempCPMK1=0;
float tempCPMK2=0;
//#end of define sensor suhu

//#start define sensor level
const int pwPin1 = 9; //this may be different depending on the Arduino being used, and the other PW pins being used.
int arraysize = 9; //quantity of values to find the median (sample size). Needs to be an odd number
//declare an array to store the samples. not necessary to zero the array values here, it just makes the code clearer
int rangevalue[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
long pulse;
int modE;
//#end of define sensor

//#start of define Kolam uk 90x30 m2
#define P_Kolam 90.0 /* Panjang kolam (m) */
#define L_Kolam 30.0 /* Lebar Kolam (m)  */
//#define T_Kolam 2070.0 /*16 cm */ 
const long T_Kolam=2642.0;  //2350
#define ALARM_HH 2000 //Alarm High level kolam
#define ALARM_LL 300  //Alarm Low level kolam
#define DELAY_0 200  //3000 /* ms; 1000 * 60 * 1 = 1 min */
#define DELAY_1 200  //1000 /* ms */
#define DELAY_2 200  //200 /* ms */

long cm, inches, ullage, levelmm;
float levelValue=0;
float pressValue = 0;
float vol = 0; //vol = P_Kolam*L_Kolam*T_Kolam
float uptime = 0;
float overjValue=0;

char c1[32];
    char c2[32];
    char c3[32];
    char c4[32];
    char covj[32];
    char cal[32];
    char* sx[]={"stpumpj=","stpmk1=","stpmk2="};
    char* sy[]={"OFF","ON","AUTO","MANUAL","TRIP","RPM"};char* sz[]={"NO","YES"};
    char* sal[]={"LL","Aman","HH"};
    int stpumpJValue = 0;int stpmk1Value = 0;int stpmk2Value = 0;int stp4Value = 0;
char pageAdd[256]; //128 256

// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 30000UL //30detik

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  // Start Initialize Temperature measurement
 sensors.begin();
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);
  // End of Initialize Temperature measurement
 
  pinMode(pwPin1, INPUT);
  // disable SD SPI
//  pinMode(4,OUTPUT);
 // digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
 //  else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}




void loop()
{
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
  {
    lastMillis = thisMillis;
 
  //start sensing of sensor until 11 data
  for(int i = 0; i < arraysize; i++)
  {                           
     baca_level();
     printall();
     rangevalue[i] = levelmm;//1007/58=17.36
    delay(1);
  }
//end of sensing sensor

  Serial.print("Unsorted: ");
  printArray(rangevalue,arraysize);
  isort(rangevalue,arraysize);
  Serial.print("Sorted: ");
  printArray(rangevalue,arraysize);
  modE = mode(rangevalue,arraysize);
  Serial.print("The mode/median is: ");
  Serial.print(modE);
 
  levelmm=modE;   
  Serial.print("levelmm : "); 
  Serial.println(levelmm);
 
  levelValue=levelmm;
   float levelM=levelValue/1000;
   vol = P_Kolam*L_Kolam*levelM;//1594.5
     vol=vol+0.5; // 1595.0
     vol=floor(vol); //1595
 
  switch (cek_alarm2(levelmm)) {
  case 1:
    Serial.print("Level : ");
    Serial.print(levelmm);
    strcpy (cal, sal[2]); //0 HH
    Serial.println(" >> Alarm HH"); //!!!!
    delay(DELAY_1);
    break;
 
  case 2:
    Serial.print("Level : ");
    Serial.print(levelmm);
      strcpy (cal, sal[0]); //LL
    Serial.println(" >> Alarm LL");
    delay(DELAY_2);
    break;   
  case 0: // no alarm
    Serial.print("Level : ");
    Serial.print(levelmm);
      strcpy (cal, sal[1]);
    Serial.println(" >> Aman");
    delay(DELAY_0);
  }
  Serial.println();
 
   pressValue=analogRead(A0);   // Serial.println(totalCount,DEC);
   overjValue=analogRead(A1);  //convert the analog data status overload jockey pump
   
    stpumpJValue=digitalRead(3);  // status pump1 //3
    stpmk1Value=digitalRead(4);   //status pump2
    stpmk2Value=digitalRead(5);    //status pump3
   
    pressValue = (pressValue/1023.0)*10.0;  //convert the analog data to press. max 20kg/cm2
    overjValue= (overjValue/1023.0)*100.0;  //convert the analog data status overload jockey pump to value (ampere)
   
    // start for temp Pompa PMK 1 dan PMK2
    Serial.print("Jumlah sensor suhu= "); 
    Serial.println(sensors.getDeviceCount());   
    // Command all devices on bus to read temperature 
    sensors.requestTemperatures(); 
    Serial.print("temp1 Pompa PMK1:   ");
   TempPMK1(Probe01);
    Serial.println();
    Serial.print("temp2 Pompa PMK2:   ");
    TempPMK2(Probe02);
    Serial.println();
    //end for temp Pompa PMK 1 dan PMK2
   
    if (overjValue>0){
    strcpy (covj, sz[0]);
    } else {
     strcpy (covj, sz[1]);          //sy[0] in here "ON" c1=stpumpJ=ON
    }
   if (stpumpJValue>0){
    strcpy (c1, sx[0]);
    strcat (c1, sy[1]);            //sy[0] in here "ON" c1=stpump1=ON
    } else {
     strcpy (c1, sx[0]);
    strcat (c1, sy[0]);
    }
  if (stpmk1Value>0){
    strcpy (c2, sx[1]);
    strcat (c2, sy[1]);            //sy[0] in here "ON" c1=stpump1=ON
    } else {
      strcpy (c2, sx[1]);
    strcat (c2, sy[0]);
    }
  if (stpmk2Value>0){
    strcpy (c3, sx[2]);
    strcat (c3, sy[1]);            //sy[0] in here "ON" c1=stpump1=ON
    } else {
      strcpy (c3, sx[2]);
    strcat (c3, sy[0]);
    }
   
    char levelBuffer[8];
    char pressBuffer[8];
    char volBuffer[8];
    char uptimeBuffer[8];
    char overjBuffer[8];
    char tpmk1Buffer[8];
    char tpmk2Buffer[8]; 
   
    dtostrf(levelmm,3,1,levelBuffer);
    dtostrf(vol,3,1,volBuffer); //vol,3,1,volBuffer);
   
    dtostrf(pressValue,3,1,pressBuffer);
    dtostrf(overjValue,3,1,overjBuffer);
   
    //dtostrf(tpmk1Value,3,1,tpmk1Buffer);
    //dtostrf(tpmk2Value,3,1,tpmk2Buffer);
    dtostrf(tempCPMK1,3,1,tpmk1Buffer);
    dtostrf(tempCPMK2,3,1,tpmk2Buffer);
   
           switch (cek_uptime(stpmk1Value,stpmk2Value)) {
          case 1:
            Serial.print("POMPA PMK 1 dan 2 ON ");
            Serial.println();
            Serial.println(" >> UPtime = volume/4000gpm");
            uptime=vol/908.498; //m3/jam
            Serial.print(uptime);Serial.print(" jam");
            delay(DELAY_1);
            break;
         
          case 2:
            Serial.print("Pompa PMK 1 atau PMK2 ON");
            Serial.println();
            Serial.println(" >> UPtime = volume/2000gpm");
            uptime=vol/454.249;
            Serial.println(uptime);Serial.print(" jam");
            delay(DELAY_2);
            break;   
          case 0: // no alarm
            Serial.print("POMPA PMK 1 & 2 OFF");
            Serial.println(" >> uptime = 0");
            delay(DELAY_0);
          }     
    dtostrf(uptime,3,1,uptimeBuffer); //vol,3,1,volBuffer);       
   sprintf(pageAdd,"/ardsafe/tambah.php?level=%s&volume=%s&alarm=%s&uptime=%s&press=%s&%s&jover=%s&%s&tpmk1=%s&%s&tpmk2=%s",levelBuffer,volBuffer,cal,uptimeBuffer,pressBuffer,c1,covj,c2,tpmk1Buffer,c3,tpmk2Buffer);
   //http://localhost/ard2/tambah.php?level=3000&volume=3000&alarm=HH&press=3.6&stpumpj=ON&jover=NO&stpmk1=ON&tpmk1=34&stpmk2=OFF&tpmk2=30

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
   
    Serial.println(pageAdd);
    Serial.println(levelmm);             //send the data to the computer
   Serial.println(modE);
   
    Serial.println(levelM);
   Serial.println(vol);
   Serial.println(volBuffer);
    Serial.println(pressValue);             //send the data to the computer
    Serial.println(pressBuffer);
Serial.println(overjBuffer);
Serial.println(tpmk1Buffer);

Serial.println(tpmk2Buffer);
Serial.println(c1);
Serial.println(covj); //send the data to the computer
    Serial.println(c1);             //
    Serial.println(c2);
    Serial.println(c3);
    Serial.println(c4);
    Serial.print("temp1 Pompa PMK1:   ");
    TempPMK1(Probe01);
    Serial.println();
    Serial.print("temp2 Pompa PMK2:   ");
    TempPMK2(Probe02);
    Serial.println();
    delay(1000);                          //wait one second before sending new data
 }   
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[256];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
         
   
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}

void printall(){         
  Serial.print("ullage");
  Serial.print(" ");
  Serial.print(ullage); //This can be made to match the measurement type you wish to have.
  Serial.println("mm"); //Typically will be the range reading increments.

   Serial.print("Level");
  Serial.print(" ");
  Serial.print(levelmm); //This can be made to match the measurement type you wish to have.
  Serial.println("mm"); //Typically will be the range reading increments.
 
}


void baca_level() {
  ullage = pulseIn(pwPin1, HIGH);
  cm = ullage/10; // converts the range to cm
  inches = cm/2.54; // converts the range to inches
 levelmm = T_Kolam - ullage;

}

int cek_uptime(int stpmk1Value,int stpmk2Value) {
  if ((stpmk1Value>0) && (stpmk2Value>0)) { //2 pompa ON
       return 1;     
  }
  else if ((stpmk1Value>0) || (stpmk2Value>0)) { // salah satupompa ON
       return 2;
  }
  return 0;
}

int cek_alarm2(int levelmm) {
  if (levelmm > ALARM_HH) { //ex: 1063
     //if (levelmm < ALARM_HH)
       return 1; //alarm HH , if val >2000mm     
  }
  else if (levelmm < ALARM_LL) {
       return 2; //alarm LL , if val < 500mm
  }
  return 0; //1063=Aman
}
 
//mediann

/*-----------Functions------------*/ //Function to print the arrays.
void printArray(int *a, int n) {

  for (int i = 0; i < n; i++)
  {
    Serial.print(a[i], DEC);
    Serial.print(' ');
  }

  Serial.println();

}

//Fungsi sort 11 data level
// sort function (Author: Bill Gentles, Nov. 12, 2010)
void isort(int *a, int n){
// *a is an array pointer function

  for (int i = 1; i < n; ++i)
  {
    int j = a[i];
    int k;
    for (k = i - 1; (k >= 0) && (j < a[k]); k--)
    {
      a[k + 1] = a[k];
    }
    a[k + 1] = j;
  }

}

//Mode function, returning the mode or median.
int mode(int *x,int n){

  int i = 0;
  int count = 0;
  int maxCount = 0;
  int mode = 0;
  int bimodal;
  int prevCount = 0;

  while(i<(n-1)){

    prevCount=count;
    count=0;

    while(x[i]==x[i+1]){
      count++;
      i++;
    }

    if(count>prevCount&count>maxCount){
      mode=x[i];
      maxCount=count;
      bimodal=0;
    }
    if(count==0){
      i++;
    }
    if(count==maxCount){//If the dataset has 2 or more modes.
      bimodal=1;
    }
    if(mode==0||bimodal==1){//Return the median if there is no mode.
      mode=x[(n/2)];
    }
    return mode;
  }
}

void TempPMK1(DeviceAddress deviceAddress)
{
tempCPMK1 = sensors.getTempC(Probe01);
   if (tempCPMK1 == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print("C1: ");
   Serial.print(tempCPMK1);
   Serial.print(" F1: ");
   Serial.print(DallasTemperature::toFahrenheit(tempCPMK1));
   } 
}

void TempPMK2(DeviceAddress deviceAddress)
{
tempCPMK2 = sensors.getTempC(Probe02);
   if (tempCPMK2 == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print("C2: ");
   Serial.print(tempCPMK2);
   Serial.print(" F2: ");
   Serial.print(DallasTemperature::toFahrenheit(tempCPMK2));
   }
   
}


for some one have more experience about send data to server with ESP8266, can sharing in this page.
thanks