blacktrooper2:
Hit there,
I know it's been a while but I'm trying to do the same and having a problem with the software serial.
My ESP8266 works fine alone without serial, as well when it's running software serial without wifi but when I try to combine both, it stops the wifi communication with computer.
Did you had the same thing ?
How is your code?
Are you like sensing with arduino and then sending data to ESP8266 ?
hi, i also get this trouble, someone help me please...
my nodeMcu work fine connect to my database before i use software serial...
but when i try get data from arduino Mega with softwareSerial to nodemcu... softwareSerial work fine but can't send data to my database
when i combine both, i receive
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>
1. my arduino mega code
/*
Measuring AC Current Using ACS712
*/
int mVperAmp = 100; // use 185 for 5A module 100 for 20A Module and 66 for 30A Module
int limit = 50;
int CT1 = 600.0 ;
String ALLIN ;
const int sensorIn1R = A1; const int sensorIn1S = A2; const int sensorIn1T = A3; //RAK 1
const int sensorIn2R = A4; const int sensorIn2S = A5; const int sensorIn2T = A6; //RAK 2
const int sensorIn3R = A7; const int sensorIn3S = A8; const int sensorIn3T = A9; //RAK 3
const int sensorIn4R = A10; const int sensorIn4S = A11; const int sensorIn4T = A12; //RAK 4
const int sensorIn5R = A13; const int sensorIn5S = A14; const int sensorIn5T = A15; //RAK 5
// RAK 1
double Voltage1R = 0; double VRMS1R = 0; double AmpsRMS1R = 0; double calibrasi1R = 0; String SR1 ;
double Voltage1S = 0; double VRMS1S = 0; double AmpsRMS1S = 0; double calibrasi1S = 0; String SS1 ;
double Voltage1T = 0; double VRMS1T = 0; double AmpsRMS1T = 0; double calibrasi1T = 0; String ST1 ;
// RAK 2
double Voltage2R = 0; double VRMS2R = 0; double AmpsRMS2R = 0; double calibrasi2R = 0;
double Voltage2S = 0; double VRMS2S = 0; double AmpsRMS2S = 0; double calibrasi2S = 0;
double Voltage2T = 0; double VRMS2T = 0; double AmpsRMS2T = 0; double calibrasi2T = 0;
void setup(){
Serial.begin(115200);
Serial1.begin(115200);
}
void loop(){
/*==================RAK 1===================*/
Voltage1R = getVPP1R();
VRMS1R = ((Voltage1R/2.0) *0.707106781);
AmpsRMS1R = ((VRMS1R * 1000)/mVperAmp)-0.110;
if (AmpsRMS1R<0.00) AmpsRMS1R = 0.00 ;
calibrasi1R = (CT1*AmpsRMS1R/5.0);
Voltage1S = getVPP1S();
VRMS1S = ((Voltage1S/2.0) *0.707106781);
AmpsRMS1S = ((VRMS1S * 1000)/mVperAmp)-0.110;
if (AmpsRMS1S<0.00) AmpsRMS1S = 0.00 ;
calibrasi1S = (CT1*AmpsRMS1S/5.0);
Voltage1T = getVPP1T();
VRMS1T = ((Voltage1T/2.0) *0.707106781);
AmpsRMS1T = ((VRMS1T * 1000)/mVperAmp)-0.110;
if (AmpsRMS1T<0.00) AmpsRMS1T = 0.00 ;
calibrasi1T = (CT1*AmpsRMS1T/5.0);
/*==================RAK 1===================*/
SR1 = (String) calibrasi1R;
SS1 = (String) calibrasi1S;
ST1 = (String) calibrasi1T;
ALLIN += SR1;
ALLIN += ",";
ALLIN += SS1;
ALLIN += "," ;
ALLIN += ST1 ;
Serial.println(ALLIN);
Serial1.println(ALLIN);
ALLIN ="";
}
/*==================RAK 1===================*/
/*==================1R===================*/
float getVPP1R()
{
float result1R;
float readValue1R;
float maxValue1R = 0;
float minValue1R = 1024;
uint32_t start_time1R = millis();
while((millis()-start_time1R) < limit)
{
readValue1R = analogRead(sensorIn1R);
if (readValue1R > maxValue1R)
{maxValue1R = readValue1R;}
if (readValue1R < minValue1R)
{minValue1R = readValue1R;}
}
result1R = ((maxValue1R - minValue1R) * 5.0)/1024.0;
return result1R;
}
/*==================1S===================*/
float getVPP1S()
{
float result1S;
float readValue1S;
float maxValue1S = 0;
float minValue1S = 1024;
uint32_t start_time1S = millis();
while((millis()-start_time1S) < limit)
{
readValue1S = analogRead(sensorIn1S);
if (readValue1S > maxValue1S)
{maxValue1S = readValue1S;}
if (readValue1S < minValue1S)
{minValue1S = readValue1S;}
}
result1S = ((maxValue1S - minValue1S) * 5.0)/1024.0;
return result1S;
}
/*==================1T===================*/
float getVPP1T()
{
float result1T;
float readValue1T;
float maxValue1T = 0;
float minValue1T = 1024;
uint32_t start_time1T = millis();
while((millis()-start_time1T) < limit)
{
readValue1T = analogRead(sensorIn1T);
if (readValue1T > maxValue1T)
{maxValue1T = readValue1T;}
if (readValue1T < minValue1T)
{minValue1T = readValue1T;}
}
result1T = ((maxValue1T - minValue1T) * 5.0)/1024.0;
return result1T;
}
2. my nodeMcu code
#include<SoftwareSerial.h>
#include "StringSplitter.h"
#include <ESP8266WiFi.h>
SoftwareSerial SUART( 4, 5); //SRX = DPin-2; STX = DPin-3
String ir1 , is1, it1 ;
String data="", tanggal="", aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm, nn, oo, pp, qq, rr, ss ;
const char* ssid = " wifi2";
const char* password = " merdeka ";
const char* host = "microdpl.000webhostapp.com";
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
Serial.begin(115200);
SUART.begin(115200);
}
void loop() {
serial1 ();
delay (1000);
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/api/gardu1/insert.php?idmesin=100&vab=" + String (ir1) +"&vbc="+String (is1)+"&vca="+String (it1);
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(2000);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
delay(10000);
data = "";
ir1="";
is1="";
it1="";
data="";
Serial.println("test");
}
void serial1 (){
if(SUART.available()){
data= SUART.readStringUntil('\n');
StringSplitter *splitter = new StringSplitter (data, ',', 3);
int itemCount = splitter->getItemCount();
ir1 = splitter->getItemAtIndex(0);
is1 = splitter->getItemAtIndex(1);
it1 = splitter->getItemAtIndex(2);
/*
Serial.print(ir1);
Serial.println(" = ");
Serial.print(is1);
Serial.println(" = ");
Serial.print(it1);
*/
SUART.flush ();
}
}