Exit status 1 'Serial' does not name a type

where is the wrong code?
anyone can help about exit status 1
'Serial' does not name a type

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
 
#define RE D5
#define DE D6
 
//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
 
byte values[11];
SoftwareSerial mod(D7,D8);

//konfigurasi wifi

const char *ssid = "ayangnya lola";
const char *password = "55555555";

//ip adress server XAMPP
const char *host = "localhost";

void setup() {

  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

//connect
Serial.print("connecting to ");
Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(".");
  }
  //jika koneksi berhasil
  Serial.println("");
  Serial.print("Connected");
  Serial.print("IP Address : ");
  Serial.println(WiFi.localIP());
}
 
void loop() {


  
  byte val1,val2,val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);
  

  
  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);
}
  
byte nitrogen(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(nitro,sizeof(nitro))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}
 
byte phosphorous(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(phos,sizeof(phos))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
   // Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}
 
byte potassium(){
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(mod.write(pota,sizeof(pota))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<7;i++){
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
   //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}  
  //proses pengiriman
  Serial.print("Connecting to");
  Serial.println(host);

  //mengirim ke alamat host
  WiFiClient client;
  const int httpPort = 80; 
  if (!client.connect(host, httpPort)){
  Serial.println("Connection failed");
  return;
  }

  //isi konten yg dikirim
  client.print(String ("GET localhost/sensor_npk/write-data.php?") +
 ("&Nitrogen = ")+ val1 + ("&Fosfor = ")+ val2 + ("&Kalium = ")+ val3 + " HTTP/1.1\r\n" +
  "Host: " + host + "\r\n" +
  "connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while(client.available() == 0) {
    if (millis() - timeout > 1000) {
      Serial.println(">>client timeout!");
      client.stop();
      return;
    }
  }
  //read all line
  while (client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  Serial.println();
  Serial.println("close connection");
}

in this part

The number of right and left curly braces does not match.
Format the code in the Arduino IDE with ctrl-T - it will be easier to find the extra or missing bracket

Yup, something goes awry after function byte potassium(){ } I think.

is not work, still error

show your revised code

@faqsycs

Your topic was moved to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

It will help you get the best out of the forum in the future.

Thank you

This code is outside of any function.

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define RE D5
#define DE D6

//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};

byte values[11];
SoftwareSerial mod(D7, D8);

//konfigurasi wifi

const char *ssid = "ayangnya lola";
const char *password = "55555555";

//ip adress server XAMPP
const char *host = "localhost";

void setup() {

  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

  //connect
  Serial.print("connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  //jika koneksi berhasil
  Serial.println("");
  Serial.print("Connected");
  Serial.print("IP Address : ");
  Serial.println(WiFi.localIP());
}

void loop() {



  byte val1, val2, val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);



  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);


}

byte nitrogen() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(nitro, sizeof(nitro)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte phosphorous() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(phos, sizeof(phos)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      // Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte potassium() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(pota, sizeof(pota)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

//proses pengiriman
Serial.print("Connecting to");
Serial.println(host);

//mengirim ke alamat host
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
  Serial.println("Connection failed");
  return;
}

//isi konten yg dikirim
client.print(String ("GET localhost/sensor_npk/write-data.php?") +
             ("&Nitrogen = ") + val1 + ("&Fosfor = ") + val2 + ("&Kalium = ") + val3 + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
  if (millis() - timeout > 1000) {
    Serial.println(">>client timeout!");
    client.stop();
    return;
  }
}
//read all line
while (client.available()) {
  String line = client.readStringUntil('\r');
  Serial.print(line);
}
Serial.println();
Serial.println("close connection");
}

still error

if i move like thi the error is
exit status 1
'nitrogen' was not declared in this scope; did you mean 'nitro'?
in line 154

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define RE D5
#define DE D6

//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};

byte values[11];
SoftwareSerial mod(D7, D8);

//konfigurasi wifi

const char *ssid = "ayangnya lola";
const char *password = "55555555";

//ip adress server XAMPP
const char *host = "localhost";

void setup() {

  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

  //connect
  Serial.print("connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  //jika koneksi berhasil
  Serial.println("");
  Serial.print("Connected");
  Serial.print("IP Address : ");
  Serial.println(WiFi.localIP());
}

void loop() {



  byte val1, val2, val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);



  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);


}
//proses pengiriman
Serial.print("Connecting to");
Serial.println(host);

//mengirim ke alamat host
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
  Serial.println("Connection failed");
  return;
}

//isi konten yg dikirim
client.print(String ("GET localhost/sensor_npk/write-data.php?") +
             ("&Nitrogen = ") + val1 + ("&Fosfor = ") + val2 + ("&Kalium = ") + val3 + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
  if (millis() - timeout > 1000) {
    Serial.println(">>client timeout!");
    client.stop();
    return;
  }
}
//read all line
while (client.available()) {
  String line = client.readStringUntil('\r');
  Serial.print(line);
}
Serial.println();
Serial.println("close connection");
}
byte nitrogen() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(nitro, sizeof(nitro)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte phosphorous() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(phos, sizeof(phos)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      // Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte potassium() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(pota, sizeof(pota)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}


Go back and read Post #8.

what it mean, i don't understand

  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);
}

That last } is where loop() ends. Everything up to the below } is outside a function.

}
byte nitrogen() {

If you remove the first mentioned } that indicates that loop ends, it's one problem less.

can you correct all the code, need it ASAP

You do not want to learn to understand the codes a little bit? This is clearly not the last mistake - you plan to ask everyone on the forum?

i've try all script code for 2 weeks, but still not work
i don't know how to finde the wrong code, because it's first time make monitoring system on NPK sensor, and i don't know what should i do

I think that I've given the correct pointer for you to fix it.

You have to wait till I'm or somebody else is in the mood, specifically after using the word ASAP. ASAP often results in people being reluctant to help; either it's a school assignment or you get paid and we don't.

Nothing is urgent on the forum. If you need it urgent, you can consider to pay someone to do it.

2 Likes

@faqsycs pay special attention to the indentation of the code that is produced by the Arduino IDE's Tools > Auto Format (Ctrl+T). This provides a nice visual representation of the overall structure of the program.

I think if you look carefully you will see that the indentation of parts of the code does not match your intended program structure. This will point you to the error.

#include <SoftwareSerial.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define RE D5
#define DE D6

//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};

byte values[11];
SoftwareSerial mod(D7, D8);

//konfigurasi wifi

const char *ssid = "ayangnya lola";
const char *password = "55555555";

//ip adress server XAMPP
const char *host = "localhost";

void setup()
{

  Serial.begin(9600);
  mod.begin(9600);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);

  //connect
  Serial.print("connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  //jika koneksi berhasil
  Serial.println("");
  Serial.print("Connected");
  Serial.print("IP Address : ");
  Serial.println(WiFi.localIP());
}

void loop()
{



  byte val1, val2, val3;
  val1 = nitrogen();
  delay(250);
  val2 = phosphorous();
  delay(250);
  val3 = potassium();
  delay(250);



  Serial.print("Nitrogen: ");
  Serial.print(val1);
  Serial.println(" mg/kg");
  Serial.print("Phosphorous: ");
  Serial.print(val2);
  Serial.println(" mg/kg");
  Serial.print("Potassium: ");
  Serial.print(val3);
  Serial.println(" mg/kg");
  delay(2000);
}

byte nitrogen()
{
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(nitro, sizeof(nitro)) == 8)
  {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++)
    {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte phosphorous()
{
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(phos, sizeof(phos)) == 8)
  {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++)
    {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      // Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

byte potassium()
{
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  if (mod.write(pota, sizeof(pota)) == 8)
  {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 7; i++)
    {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i],HEX);
    }
    //Serial.println();
  }
  return values[4];
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.