Go Down

Topic: esp8266 wemos d1mini (Read 651 times) previous topic - next topic

verdi

saya pakai wemos untuk mengirim data ke web. untukk mengirim ke localhost sudah bisa. tapi mengirim ke host yang sudah saya beli kenapa tidak bisa. pakai program yang sama hanya mengganti ip nya saja. apa ada yang pernah mencobanya memakai esp8266 wemos d1 mini. berikut programnya

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

// Replace with your network details
const char* server = "103.247.9.184";
const char* ssid = "****";
const char* password = "****";
const char* SensorID= "ESP001";
const int sensorIn = A0;

int mVperAmp =80;

WiFiClient client;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

void setup() {
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);

// Connecting to WiFi network

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

void loop() {

Voltage = getVPP();
VRMS = ((Voltage/ 2.0) * 234375);
AmpsRMS = (VRMS / 4000000) * mVperAmp;

if (client.connect(server,80)){
Serial.print("Posting data");
Serial.print("Nilai Arus : ");
Serial.println(AmpsRMS);
client.println("GET /tes/index.php?AmpsRMS="+String(AmpsRMS)+"&&SensorID="+String(SensorID)+" HTTP/1.1");
client.println("HOST: 103.247.9.184");
client.println("Connection: close");
client.println();

while (client.connected()&&!client.connected()) delay(1);
while (client.connected() || client.available()){
  char c = client.read();
  Serial.print(c);
}
client.stop();
Serial.println();
}
delay(1000);
}

float getVPP()
{
float result;

int readValue;             //value read from the sensor
int maxValue = 0;          // store max value here
int minValue = 1024;          // store min value here

 uint32_t start_time = millis();
 while((millis()-start_time) < 1000) //sample for 1 Sec
 {
     readValue = analogRead(sensorIn);
     // see if you have a new maxValue
     if (readValue > maxValue)
     {
         /*record the maximum sensor value*/
         maxValue = readValue;
     }
     if (readValue < minValue)
     {
         /*record the maximum sensor value*/
         minValue = readValue;
     }
 }
 
 // Subtract min from max
 result = ((maxValue - minValue) * 5.0)/1024.0;
   
 return result;
}

Go Up