Wifi shield sends email via pushingbox!!Help NEEDED!!

Bluetooth, XBee, RF......

Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby EmilyQiQi » Thu Aug 18, 2016 6:00 pm

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:)
EmilyQiQi
Freshie
 
Posts: 4
Joined: Thu Aug 18, 2016 5:50 pm

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby bengchet » Thu Aug 18, 2016 6:16 pm

Hi,

Have you tried get devid from login into pushingbox website and creating application?
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby EmilyQiQi » Sat Aug 20, 2016 8:47 pm

Hi!! Thanks for the comment.!:) I have used the Device ID from the scenario that I have created. Is it correct?? It starts from the letter "v". Hope to hear from you soon. Thank You
EmilyQiQi
Freshie
 
Posts: 4
Joined: Thu Aug 18, 2016 5:50 pm

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby bengchet » Sun Aug 21, 2016 12:26 pm

Hi,

Ok. You can try couple of things here.

First, type http://api.pushingbox.com/pushingbox?devid=[Your devid] at your browser, then check if you have received any emails.
If you can get emails, meaning the link is correct.

if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}

Secondly, this chunk of coding is not complete for receiving response from pushingbox, you can refer to the pushingbox example sketch to see how receive response coding should be written.

// 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();


This whole chunk is not needed in void loop because you only need to connect to pushingbox when push button is pressed.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby EmilyQiQi » Thu Aug 25, 2016 7:56 pm

Hi!

I have found several codes about pushingBox from its websites, which is here:

https://github.com/Clement87/PushingBox ... shield.ino

This is the code created by pushingbox for Arduino Wifi-shield: it also had the code

"
if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}

I don't really understand what by it means I will get 200ok after writing respons from pushingBox.

I faced one problem while compiling the sketch. I think it may be one of the reason why the wifi shield is unable to send the email, which is :

//sending request to pushingbox if devid1 is HIGH,
sendToPushingBox(DEVID1);

It says sendToPushingBox is not declared in this scope.
while on the sketch, sendToPushingBox should be coloured right? It is not in my sketch.

Well, thank you for answering my question. Hope to hear from you soon. :)
EmilyQiQi
Freshie
 
Posts: 4
Joined: Thu Aug 18, 2016 5:50 pm

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby bengchet » Fri Aug 26, 2016 4:40 pm

Hi,

Attached is small snippet of coding. Not tested yet but should be able to working. I also change button to active low, meaning it will trigger function sendToPushingBox if the state is LOW. Feel free and test it out and compare with original source code.

Have fun!
Attachments
test_wifi.zip
(1.36 KiB) Downloaded 287 times
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Wifi shield sends email via pushingbox!!Help NEEDED!!

Postby EmilyQiQi » Mon Sep 12, 2016 10:35 pm

Hi,

Thank you for the sketch. It works when I pushed the pushbutton. Sorry for late reply because I am busy with my exam few weeks ago. Thank you very much. Hope you have a nice day.:)

Cheers,
Emily
EmilyQiQi
Freshie
 
Posts: 4
Joined: Thu Aug 18, 2016 5:50 pm


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 18 guests

cron