Skip to content

ESP hangs up #50

Closed
Closed
@iMarvinS

Description

@iMarvinS

I´m trying to build a wireless PIR sensor from a ESP-07.
I have the code already working but after a undefined time the firmware hangs up and logs some unusual stuff on the UART.
The IDE I´ve used is built by myself and is the most actual version fresh from the esp8266 branch.

The Sketch:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const int pirPin = 2;
const char* ssid = "Home 7362";
const char* password = "mysecretpasswordwhichnobodyshouldknowxDD";
const char* host = "192.168.178.24";
const int port = 80;
int lastMillis;
bool lastState;
WiFiClient wifiClient;

void pirInterrupt();

void setup() {
  Serial.begin(9600);

  WiFi.begin(ssid, password);
  Serial.println("");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(2, INPUT);
  //attachInterrupt(2, pirInterrupt, FALLING);
  lastMillis = millis();

  while(digitalRead(pirPin) == LOW){
    Serial.println("Calibrating...");
    delay(200);
  }

}

void loop() {
  if(digitalRead(pirPin) == HIGH && lastState == LOW && millis() - lastMillis >= 5000){
      pirInterrupt();
    lastMillis = millis();
  }
  lastState = digitalRead(pirPin);

  delay(20);
}

void pirInterrupt() {
  Serial.println("PIR: alarm triggered!");

  if (!wifiClient.connect(host, 80)) {
    Serial.println("Connection failed!");
    return;
  }

  String url = "/pirpush/push.php";
  url += "?message=Der+Postmann+ist+da!";
  url+= "&id=1";

  Serial.print("Requesting URL: "); 
  Serial.println(url);

  wifiClient.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  /*
  delay(50);

  while(wifiClient.available()){
    String line = wifiClient.readStringUntil('\r');
    Serial.print(line);
  }
  */
  Serial.println();
  Serial.println("Closing connection.");
}

The output on serial:
bildschirmfoto 2015-04-04 um 18 29 21

What is the issue with it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions