add rem statements to this code please

I am trying to modify this program but it is beyond my current knowledge. it is written for the esp8266-01 but i am using a nodemcu. i would like to add other sensors to other gpio ans send different messages depending on which sensor is tripped. for example 2 sump pumps. maybe a simple motion sensor i can turn on while on vacation. if someone could add rem statement to this program or suggest how to do this it would be appreciated. thankyou. and all the credit for work so far goes to random nerd tutorios.

/*
Created by Rui Santos

All the resources for this project:

Based on some ESP8266 code examples
*/

#include <ESP8266WiFi.h>

const char* ssid = "xxxxxx";/ my ssd
const char* password = "xxxx";/my password
const char* host = "maker.ifttt.com";
const char* apiKey = "xxxxx";/ my app key i know this

int pin = 2;
volatile int state = false;
volatile int flag = false;
const char* door_state = "closed";

unsigned long previousMillis = 0;
const long interval = 3000;

void changeDoorStatus() {

unsigned long currentMillis = millis();

if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;

state = !state;
if(state) {
door_state = "opened";
}
else{
door_state = "closed";
}
flag = true;
Serial.println(state);
Serial.println(door_state);
}

}

void setup() {
Serial.begin(115200);
delay(100);
Serial.println("Preparing the Door Status Monitor project...");

pinMode(pin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(pin), changeDoorStatus, CHANGE);

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() {

if(flag){
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 = "/trigger/door_status/with/key/";
url += apiKey;

Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: 13\r\n\r\n" +
"value1=" + door_state + "\r\n");
flag = false;
}
delay(10);
}

What's a rem statement?

Please use code tags when posting code.

AWOL:
What's a rem statement?

Come on. You're not that young. :wink:

I've never heard of it.
What is it?

AWOL:
I've never heard of it.
What is it?

You must be REALLY young - REM (for REMARK) were comments in BASIC code (especially the original stuff that was all about line numbers and GOTO etc.) Sheesh - thanks for making me feel REALLY old now :o

You mean comments ?
Why didn't you say comments?

I thought it was something to do with Southern Democrat utterances by Michael Stipe.

AWOL:
You mean comments ?
Why didn't you say comments?

I thought it was something to do with Southern Democrat utterances by Michael Stipe.

Because REM statements mean remarks, not comments, comments are critiques, remarks are spoken statements of an opinion or thought.

:wink: just yanking your chain. REM statements bring me back to 1978 and TRS-80 Level I Basic. 38 years ago, My first experience with a computer. Other than in Science Fiction of course!

Chuck.

Well, they're kind of the reverse of comments in C - those are typically at the end of the line or on a line by themselves whereas the REM statements started with REM at the beginning of the line (you can still use them in DOS command windows :frowning: ). Now to get really old, how many remember the comment column in the old punch cards when you were programming in FORTRAN :o

Yeah, I think that's me in the corner, that's me in the spotlight, losing my religion.
That's a REM statement.

(I started BASIC programming in 1975. Gave it it up in 1977. Still get the flashbacks. You weren't there man)

yes I am old 50+ so yes a rem statement is a remark statement. it is used to describe what is going on in that line. so Ii guess I need comments

ps I took basic in 1984 on an ibm286 pc oddly enough basic isn't that different than the arduino ide

I'm sad to say that I remember REM statements too. (About all I do remember from that era. :frowning: )

chucktodd:
REM statements bring me back to 1978 and TRS-80 Level I Basic. 38 years ago, My first experience with a computer.

This was my first love too. :slight_smile:

ls1swap:
I am trying to modify this program but it is beyond my current knowledge. it is written for the esp8266-01 but i am using a nodemcu. i would like to add other sensors to other gpio ans send different messages depending on which sensor is tripped. for example 2 sump pumps. maybe a simple motion sensor i can turn on while on vacation. if someone could add rem statement to this program or suggest how to do this it would be appreciated. thankyou. and all the credit for work so far goes to random nerd tutorios.

For future reference, code should always be posted between code tags, not inline.
Code tags are produced using the </> button, or you can type them manually. Square brackets like the following:-

[code]Paste your code here[/code]
It will appear in a block like this

I've fixed the couple of comments that were already in the code, but typed incorrectly. Is that what you meant?
(I can't compile to check for errors, because I don't have the "ESP8266WiFi" library.)

/*
 Created by Rui Santos

 All the resources for this project:
 http://randomnerdtutorials.com/

 Based on some ESP8266 code examples
*/

#include <ESP8266WiFi.h>

const char* ssid = "xxxxxx";            // my ssd
const char* password = "xxxx";          //my password
const char* host = "maker.ifttt.com";
const char* apiKey = "xxxxx";           // my app key i know this

int pin = 2;
volatile int state = false;
volatile int flag = false;
const char* door_state = "closed";
unsigned long previousMillis = 0;
const long interval = 3000;

void changeDoorStatus()
{
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval)
    {
        previousMillis = currentMillis;
        state = !state;
        if (state)
        {
            door_state = "opened";
        }
        else
        {
            door_state = "closed";
        }
        flag = true;
        Serial.println(state);
        Serial.println(door_state);
    }
}

void setup()
{
    Serial.begin(115200);
    delay(100);
    Serial.println("Preparing the Door Status Monitor project...");

    pinMode(pin, OUTPUT);
    attachInterrupt(digitalPinToInterrupt(pin), changeDoorStatus, CHANGE);

    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()
{
    if (flag)
    {
        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 = "/trigger/door_status/with/key/";
        url += apiKey;

        Serial.print("Requesting URL: ");
        Serial.println(url);
        client.print(String("POST ") + url + " HTTP/1.1\r\n" +
                     "Host: " + host + "\r\n" +
                     "Content-Type: application/x-www-form-urlencoded\r\n" +
                     "Content-Length: 13\r\n\r\n" +
                     "value1=" + door_state + "\r\n");
        flag = false;
    }
    delay(10);
}

No but Tham you. Those were my added reminder statements put in after I pasted code to forum ( which I now know I shouldn't do). The program as it is runs just fine,but I want to add more function to it by using more gpoi. Unfortunately I can't do that if I don't understand the current code.

ls1swap:
No but Tham you. Those were my added reminder statements put in after I pasted code to forum ( which I now know I shouldn't do). The program as it is runs just fine,but I want to add more function to it by using more gpoi. Unfortunately I can't do that if I don't understand the current code.

So what you are asking us to do is:

Please explain what this code does and how it does it.

Is this an accurate statement of your request?

A couple of question for you:

  • Does this code work?
    What do you expect it to do?
    And what does it actually do?
  • What are the additional functions you want it to do?
  • What is "gpoi"? I am unfamiliar with that acronym.

Chuck.

Thanks for the laughs. my TI-99/4A used REM statements as well.

so we are a bunch of guys who experienced the 60's.
but that does not explain the OP asking for REM statements......

Gpoi = general purpose input output. It is essentialy pin on esp8266. This program send a email through ifttt when gpoi 2 is high. It was written for the esp8266-01 I am using a esp826612e (nodemcu). The node mcu has additional gpoi and I want to use them for additional sensors . For instance I have two sump pumps at my house I want to receive a email when one fails. I would also like a simple motion sensor for when I am on vacation.

ls1swap:
Gpoi = general purpose input output.

You mean GPIO, not Gpoi.

This is a link to the project

My IBM 360 running WatFor used a "C" in column 5 (or 6?, really can't remember).....

JimboZA:
My IBM 360 running WatFor used a "C" in column 5 (or 6?, really can't remember).....

C, c, D and a few other things are still valid for FORTRAN.

I've used 'PICBasic Pro' for my simpler PIC projects for years, and "rem" is still a valid way of starting a comment in that language, although ' and ; are more commonly used. Not sure about other modern Basic variants like 'Visual Basic'.