WiFi ESP8266在Arduino监视器中修改我的功率值

时间:2017-09-06 14:12:34

标签: arduino arduino-uno esp8266

Here is a link to openenergy monitor where I got the current sensor, you can find the type CT3100.

我正在使用Arduino Uno开发能量监视器。我已经能够获得Arduino监视器中总功率的值(正确)。我想使用ESP8266 WiFi模块将数据发送到数据库。

出现的问题是当我将ESP模块添加到Arduino时,我在监视器中获得的总功率值不再正确。

void setup(){  
 wifi.setBootMarker(F("Version:0.9.2.4]\r\n\r\nready"));
 softser.begin(9600); // Soft serial connection to ESP8266
 Serial.begin(9600);;
 emon1.current(1, 55.6);       // Current: input pin, calibration.
 char buffer[50];
 Serial.print(F("Hard reset..."));
 if(!wifi.hardReset()) {
  Serial.println(F("no response from module."));
  for(;;);
 }
 Serial.println(F("OK."));
 Serial.print(F("Soft reset..."));
 if(!wifi.softReset()) {
  Serial.println(F("no response from module."));
  for(;;);
 }
 Serial.println(F("OK."));
 Serial.print(F("Checking firmware version..."));
 wifi.println(F("AT+GMR"));
 if(wifi.readLine(buffer, sizeof(buffer))) {
  Serial.println(buffer);
  wifi.find(); // Discard the 'OK' that follows
 } else {
  Serial.println(F("error"));
 }
 Serial.print(F("Connecting to WiFi..."));
 if(wifi.connectToAP(F(ESP_SSID), F(ESP_PASS))) {
  Serial.print(F("OK\nChecking IP addr..."));
  wifi.println(F("AT+CIFSR"));
  if(wifi.readLine(buffer, sizeof(buffer))) {
   Serial.println(buffer);
   wifi.find(); // Discard the 'OK' that follows
  }
 }
}
void loop(){
 Serial.print(F("Connecting to host..."));
 if(wifi.connectTCP(F(HOST), PORT)) {
  Serial.print(F("OK\nRequesting page..."));
  double Irms = emon1.calcIrms(1480);      //extract Irms into Variable
  double power = Irms*208;
  String data;
  data+="{\"IdClient\":";
  data+=Client_id;
  data+=",\"Nom\":\"";
  data+=Nom;
  data+="\",\"Irms\":";
  data+=Irms; 
  data+=",\"Power\":";
  data+=power;
  data+="}";       
  softser.print(data);
  String Post="POST / HTTP/1.1\r\nHost: 13.81.244.50\r\nContent-Type: 
  application/json\r\nContent-Length:";
  Post+=String(data.length());
  Post+="\r\n\r\n";
  Post+=data;
  Post+="\r\n\r\n";  
  String Send = "AT+CIPSEND=";
  Send+=String(Post.length());
  wifi.println(Send); 
  if (wifi.find(F(">"))){
   wifi.print(Post);
  }
  //Test
  if(wifi.find(F("OK"), true)) {
   Serial.println(F("found!"));
  } else {
   Serial.println(F("not found."));
  }
  wifi.closeTCP();
 }   else { // TCP connect failed
  Serial.println(F("D'oh!"));
 }
 delay(1000);
}

0 个答案:

没有答案