-3
int temp=A0;
#include<stdlib.h>
#include <SoftwareSerial.h>

#define SSID "rab"
#define PASSWORD "rakesh1234"
#define IP "184.106.153.149" // thingspeak.com
String GET = "GET /update?key=B8B8E4FC1K541QZQ&field1=";
SoftwareSerial monitor(0, 1); // RX, TX
SoftwareSerial mySerial(5, 6); // RX, TX
int p1=0,p2=0,p3=0;
int i=0;
int j=0;

void setup() {
  pinMode(A0,INPUT);
  Serial.begin(115200);
  monitor.begin(115200);
  mySerial.begin(9600);
  sendDebug("AT");
  delay(2000);
  if(Serial.find("OK")) {
    monitor.println("RECEIVED: OK");
    Serial.println("RECEIVED: OK");
  }
  connectWiFi();
}

unsigned char buf[50];

void loop() {
   while(!mySerial.available());
   if(mySerial.read() == '#') {
     for(int i=0;i<12;i++) {
       while(!mySerial.available());
       buf[i] = mySerial.read();
     }
     buf[3] =0;
     buf[7]=0;
     buf[11]=0;
     p1 = atoi((const char *)&buf[0]);
     p2 = atoi((const char *)&buf[4]);
     p3 = atoi((const char *)&buf[8]);
     delay(1000);
   }

   long int SensorValue=analogRead(temp);
   SensorValue=SensorValue*5000;
   SensorValue=SensorValue/1024;
   SensorValue=SensorValue/10;
   SensorValue=SensorValue*9;
   SensorValue=SensorValue/5;
   SensorValue=SensorValue+32;
   String tempF=String(p1);
   String tempFF=String(p2);
   String tempFFF=String(p3);
   String tempFFFF=String(SensorValue);

   for(int j=0;j>-1;j++) {
     **j= Serial.read(int p1, int p2, int p3);**
   }
   while(Serial.available()==j)
     updateTemp(tempF,tempFF,tempFFF,tempFFFF);
   while(1) {}
 }

 void updateTemp(String tempF1 ,String tempF2, String tempF3,  String tempF4) {
   String cmd = "AT+CIPSTART=\"TCP\",\"";
   cmd += "api.thingspeak.com";
   cmd += "\",80";
   sendDebug(cmd);
   delay(1000);
   if(Serial.find("Error")) {
     monitor.print("RECEIVED: Error");
     Serial.print("RECEIVED: ERROR");
     return;
   }
   cmd = GET;
   cmd += tempF1;
   cmd += "&field2=";
   cmd += tempF2;
   cmd +="&field3=";
   cmd +=tempF3;
   cmd +="&field4=";
   cmd +=tempF4;
   cmd += "\r\n";
   Serial.print("AT+CIPSEND=");
   Serial.println(cmd.length());
   if(Serial.find(">")) {
     monitor.print(">");
     monitor.print(cmd);
     Serial.print(cmd);
   } else {
     sendDebug("AT+CIPCLOSE");
   }
   if(Serial.find("OK")) {
     monitor.println("RECEIVED: OK");
   } else {
     monitor.println("RECEIVED: Error");
   }
 }

 void sendDebug(String cmd) {
   monitor.print("SEND: ");
   monitor.println(cmd);
   Serial.println(cmd);
 }

 boolean connectWiFi() {
   Serial.println("AT+CWMODE=1");
   delay(2000);
   String cmd="AT+CWJAP=\"";
   cmd+=SSID;
   cmd+="\",\"";
   cmd+=PASSWORD;
   cmd+="\"";
   sendDebug(cmd);
   delay(1000);
   if(Serial.find("OK")) {
     monitor.println("RECEIVED: OK");
     return true;
   } else {
     monitor.println("RECEIVED: Error");
     return false;
   }
 }

This is my code. I am getting an error as "exit status 1 expected primary-expression before 'int'"

Please help me.

Thank you.

  • Please reformat your code properly so we can read it. Also, what line number does the error happen at? – Majenko Apr 8 '17 at 15:36
1

You are doing Serial.read() wrong with:

Serial.read(int p1, int p2, int p3);

Serial.read() takes no parameters per https://www.arduino.cc/en/Serial/read

Maybe you want to try parseInt() instead?

1

Your problem is that your are using asterisks ("*")

   for(int j=0;j>-1;j++) {
     **j= Serial.read(int p1, int p2, int p3);**
   }

The asterisk in C/C++ is the pointer operator. You use to get the value pointed by a pointer.

The expression **j means that j is a pointer to a pointer that points something. That's is meaningless here.

Then, the last ** is readed as another pointer to a pointer, and the compiler is expecting a variable or expression that give the value for the pointer, but found "}", which is an error.

You probably tried to comment out that line of code after the compiler barks at the Serial.read(), which, as Dave X pointed out, is illegal, because Serial.read() takes no arguments.

And, the syntax function(int x) is only use for declaring a function, not for calling one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.