Hi, my name is Emily. I am quite new in programming and dealing with Arduino. Recently, I am working on a weekend project that can send email via pushingbox while the pushbutton is high. The sketch I coded can connect to the internet and detects the signal from pushbutton. Unfortunately, it is unable to send email via pushingbox. (it stops at the line where i put "it stops here")
Here is the code:
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
#define WiFi wifi
ESP8266Client client;
char wifissid[] = "___"; // your network SSID (name)
char wifipass[] = "___"; // your WPA network password
char DEVID1[] = "____"; //Scenario : "The mailbox is open"
//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 7; // Example : the mailbox switch is connect to the Pin 3
// Debug mode
boolean DEBUG = true;
char serverName[] = "api.pushingbox.com";
boolean pinDevid1State = false; // Save the last state of the Pin for DEVID1
boolean lastConnected = false;
void setup() {
Serial.begin (9600);
pinMode(pinDevid1, INPUT);
Serial.print("Connecting to ");
Serial.println(wifissid);
if (!WiFi.begin(2, 3)) {
Serial.println("WiFi shield not present");
while (true); // don't continue
}
while (!WiFi.connectAP(wifissid,wifipass)) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void loop() {
////
// Listening for the pinDevid1 state
////
if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON
{
if(DEBUG){Serial.println("pinDevid1 is HIGH");}
pinDevid1State = true;
sendToPushingBox(DEVID1);
}
if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
if(DEBUG){Serial.println();}
if(DEBUG){Serial.println("disconnecting.");}
client.stop();
}
lastConnected = client.connected();
}
//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]){
client.stop(); if(DEBUG){Serial.println("connecting...");}
if(client.connect(serverName, 80)) {
if(DEBUG){Serial.println("connected");}
if(DEBUG){Serial.println("sendind request");} ---It stops at here.
client.print("GET /pushingbox?devid=");
client.print(devid);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(serverName);
client.println("User-Agent: Arduino");
client.println();
}
else {
if(DEBUG){Serial.println("connection failed");}
}
}
I urgently need your help to complete my project. Thank you very much and hope you leave some advice for me:)