Hello,
has anyone managed to send a GET command to generate a notification with pushingbox.com?
or send a email with the ESP8266 (has someone a example code?)
#define SSID "WIFI_AP"
#define WIFIPASS "WIFI_PASSWD"
#define DSTIP "213.186.33.19"
#define DSTHOST "api.pushingbox.com"
#define DSTPORT 80
#define SERIAL_BUFFER_SIZE 256
int counter = 0;
char incomingByte;
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
espInit();
}
void loop() {
sendIotData();
while (Serial1.available())
{
char c = Serial1.read();
Serial.print(c);
if (c == '\r') Serial.print('\n');
}
while(1);
}
void espInit() {
Serial1.println("AT+RST");
Serial.println("AT+RST");
if(Wait4String("ready", 5000)) {
while(Serial1.available()) { Serial1.read();}
Serial.println("WiFi - Module is ready");
}else{
Serial.println("Module dosn't respond.");
while(1);
}
delay(500);
Serial1.println("AT+CWMODE=1");
Serial.println("AT+CWMODE=1");
delay(500);
// Join WiFi Network
Serial.println("Join WiFi");
Serial1.print("AT+CWJAP=\"");
Serial1.print(SSID);
Serial1.print("\",\"");
Serial1.print(WIFIPASS);
Serial1.println("\"");
if(Wait4String("OK", 5000)) {
while(Serial1.available()) { Serial1.read();}
Serial.println("WiFi - connected");
}else{
Serial.println("WiFi - not connected");
while(1);
}
delay(500);
}
void sendIotData(){
String startcommand = "AT+CIPSTART=\"TCP\",\"" + String(DSTHOST) + "\", 80";
Serial1.println(startcommand);
Serial.println(startcommand);
//test for a start error
if(Serial1.find("Error")){
Serial.println("error on start");
return;
}
//create the request command
String sendcommand = "GET /pushingbox?devid=<MYDEVID> HTTP/1.1\r\nHost: api.pushingbox.com\r\nUser-Agent: ESP8266\r\n";
//send
Serial1.print("AT+CIPSEND=");
Serial1.println(sendcommand.length());
Serial.print("\nlaenge:");
Serial.println(sendcommand.length());
while (Serial1.available())
{
char c = Serial1.read();
Serial.write(c);
if (c == '\r') Serial.print('\n');
}
Serial.print(sendcommand);
Serial1.print(sendcommand);
while (Serial1.available())
{
char c = Serial1.read();
Serial.write(c);
if (c == '\r') Serial.print('\n');
}
Serial.println("====");
}
bool Wait4String(String S, int Time) {
int L = S.length();
String T = String(" ");
while(Time>0) {
if (Serial1.available()) {
char c = Serial1.read();
T = T + String(c);
if (T.length() > L) T = T.substring(1);
if (S.charAt(0) == T.charAt(0))
if (S.compareTo(T) == 0) return true;
}
else {
delay(1);
Time--;
}
}
return false;
}
String Wait4String(int Time) {
String T = String("");
while(Time>0) {
if (Serial1.available()) {
char c = Serial1.read();
T = T + String(c);
}
else {
delay(1);
Time--;
}
}
return T;
}
i have tried using your code with esp8266 using arduino ide version 1.6.1 but i get this error message
test.ino:21:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'void sendToPushingBox(String)':
test.ino:64:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean connectWiFi()':
test.ino:95:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean softwarereset()':
test.ino:112:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'void reset()':
test.ino:125:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cwmode3()':
test.ino:135:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cipmux0()':
test.ino:148:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cipmode0()':
test.ino:161:3: error: 'Serial1' was not declared in this scope
Error compiling.