Hi everyone,
I'm new to this forum and programming in general so forgive me in advance if my questions seem a bit basic.
Before I begin detailing my problem, let me explain what I'm doing. My goal is to create a PIR motion sensor located in a hallway and linked to and EasyIoT server. This is both for utility and to learn along the way. The idea is to then use Pushbullet, (and a tutorial that I found on another forum) to send my phone and computer a push notification when there is motion. (Doesn't seem impossible to me...)
Because of the location of the sensor, (it must be small/somewhat hidden) and cannot use a standard wall plug as power source. No problem, I've figured a solution to that using a Lipo and a PowerBoost module.
The PIR sensor is 5V input with 3.3V logic. My reasoning behind using the feather was that it would solve many things at once: FDTI, charger for my lipo, ESP8266 module, 3.3v logic, and 5V out (for the PIR). Again I want to keep it as small as possible.
Now here comes my issue/error. I am programming the Feather using Arduino IDE, having set my board to "Generic ESP8266 Module" as instructed in the manual. I am not too familiar with coding, so I started looking for examples. I found this on iot-playground which I think should be perfect (correct me if I'm wrong):
Below is my code and the error following when I tried to upload. In my searching the web I found the biggest cause to be missing libraries, but those are installed in the same location as the default libraries. At this stage my only goal is to have the PIR sensor communicate with the IoT Server.
Again, I am very new to this, any help, explanations, tutorials, etc, would be greatly appreciated.
Thanks,
Luigi
p.s. I attached the error code in a .txt file because it was making my post too long.
/*
Created by Igor Jarc
See http://iot-playground.com for details
Please use community forum on website do not contact author directly
External libraries:
- https://github.com/adamvr/arduino-base64
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#include <ESP8266WiFi.h>
#include <Base64.h>
//AP definitions
#define AP_SSID "AeroWifi"
#define AP_PASSWORD "xxxxx"
// EasyIoT server definitions
#define EIOT_USERNAME "xxxxxxx"
#define EIOT_PASSWORD "xxxxxxxx"
#define EIOT_IP_ADDRESS "xxx.xxx.x.xxx"
#define EIOT_PORT "80"
#define EIOT_NODE "N20S0"
#define INPUT_PIN 2
#define USER_PWD_LEN 40
char unameenc[USER_PWD_LEN];
bool oldInputState;
void setup() {
Serial.begin(115200);
pinMode(INPUT_PIN, INPUT);
wifiConnect();
char uname[USER_PWD_LEN];
String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);
str.toCharArray(uname, USER_PWD_LEN);
memset(unameenc,0,sizeof(unameenc));
base64_encode(unameenc, uname, strlen(uname));
oldInputState = !digitalRead(INPUT_PIN);
}
void loop() {
int inputState = digitalRead(INPUT_PIN);;
if (inputState != oldInputState)
{
sendInputState(inputState);
oldInputState = inputState;
}
}
void wifiConnect()
{
Serial.print("Connecting to AP");
WiFi.begin(AP_SSID, AP_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void sendInputState(bool inputState)
{
WiFiClient client;
while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
Serial.println("connection failed");
wifiConnect();
}
String url = "";
String command = "";
if (inputState)
command = "ControlOn";
else
command = "ControlOff";
url = "/Api/EasyIoT/Control/Module/Virtual/"+ String(EIOT_NODE) + "/"+command; // generate EasIoT server node URL
Serial.print("POST data to URL: ");
Serial.println(url);
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
"Connection: close\r\n" +
"Authorization: Basic " + unameenc + " \r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(100);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Connection closed");
} - See more at: http://www.esp8266.com/viewtopic.php?f=32&t=8498&p=0&e=0&sid=a8692be780603a8eefb81c48ab289e4c#sthash.ujjbgPfy.dpuf
ErrorCode.txt (18.4 KB)