-->
Page 1 of 2

Compiler gets stuck

PostPosted: Mon Jun 01, 2015 1:51 pm
by rarbolay
Guys, need some assistance. I rewrote a LUA code I was running on a 01 to Arduino. I hit the compiler and it's now getting stuck. It goes 25% or so and it stops. Could someone take a look?

Code: Select all// A PIR sensor that sends status to web server. Compiled on Arduino IDE 1.6.4 and written for ESP8266 (ESP-01)
// based upon:
// PIR sensor tester by Limor Fried of Adafruit, Andy Reischle (AReResearch)
// and John Park's published work here: http://blog.makezine.com/projects/pir-sensor-arduino-alarm/


 
#include "ESP8266WiFi.h"

const char* ssid     = "M********g"
const char* password = "**********";
const char* SensorID = "MailBox";

int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = 0;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {

  pinMode(inputPin, INPUT);     // declare sensor as input
  Serial.begin(115200);
 
 //Connect to AP
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid); 
  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());
}


void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == 1) {            // check if the input is 1
     
    delay(150);   
    if (pirState == 0) {
      // we have just turned on
      Serial.println("Motion detected!");
      SendAlarm;
      // We only want to print on the output change, not state
      pirState = 1;
    }
  } else {
     
      delay(300);   
      if (pirState == 1){
      // we have just turned off
      Serial.println("Motion ended!");
      SendClear;
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

// Send alarm to Fred (FRED is the Web Server)
void SendAlarm()
{
 WiFiClient client;
 String url = ("/alarm.php?SensorID=", "SensorID", "&status=ALARM");
 
  Serial.print("Sending web message to: ");
  Serial.println(url);

  // This will send the request to the server

if

  (client.connect("172.16.0.1", 80))
 
  {
  client.println("POST /add.php HTTP/1.1");
  client.println("Host: MOMMABUG.HOME");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.print("Content-Length: ");
  client.println(SensorID(), "&status=ALARM");
  client.print();
}
 
 if (client.connected()) {
   client.stop():
}
}

// Send clear to Fred

void SendClear()
{
  String url = ("/alarm.php?SensorID=", "SensorID", "&status=CLEAR");
  WiFiClient client;
 
  Serial.print("Sending web message to: ");
  Serial.println(url);

  // This will send the request to the server

if
{
  client.connect("172.16.0.1", 80)
  client.println("POST /add.php HTTP/1.1");
  client.println("Host: MOMMABUG.HOME");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.print("Content-Length: ");
  client.println("SensorID" (), "&status=CLEAR");
  client.print();
}
 
 if (client.connected()) {
   client.stop():
}
}

Re: Compiler gets stuck

PostPosted: Mon Jun 01, 2015 2:41 pm
by andymule
I experience "the stuck compiler" from time to time as well. I think 100% of the time it has been an error in my code, and the compiler seems to not be able to figure out what's happening. Your best bet is to comment out parts of your code and see what makes it works.

Just from looking quickly at your code this line looks suspect:
Code: Select all  client.println("SensorID" (), "&status=CLEAR");

those () might be confusing the compiler into a loop.

Re: Compiler gets stuck

PostPosted: Mon Jun 01, 2015 6:49 pm
by rarbolay
You were close. It was the client.print() line that put it in a loop.

Re: Compiler gets stuck

PostPosted: Mon Jun 01, 2015 7:16 pm
by andymule
Ah, nice!

This still looks wrong to me:
Code: Select allclient.println("SensorID" (), "&status=CLEAR");


Especially because you also have this elsewhere in your code:
Code: Select allclient.println(SensorID(), "&status=ALARM");


I bet if you fix this line here, you'll be able to compile with your
Code: Select allclient.print()

although you probably also want that to be:
Code: Select allclient.println()

so it closes the line?

anyway, cheers!