I’ve been successful with posting data to my php mailto: server using the ESP8266 from sparkfun. Basically I have two pins that go high and it sends text messages from my mailto: server to a group in the database, I’m really wanting to convert this code to work with Particle rather than the ESP. I get a good compile and it works fine on the ESP so is there anyone who knows how to write these same calls using the Particle. I’ve written it 100 ways but can’t get a good compile. I’m doing something wrong but I can’t figure out what.
The code looks like this:
:#include ESP8266WiFi.h> // you have to retag this include
:#include WifiClient.h> //retag this one too
:#include string.h> // and this one
extern "C" {
:smile: #include "user_interface.h"
uint16 readvdd33(void);
}
int inputSig = 10; //Declare input pin 10
int inputSig2 = 11; //Declare input pin 11
const char* ssid = "MyNetworkID"; //access my iphone SSID
const char* password = "MyPassword"; // Use my phone's Password
const char* host = "72.167.183.14"; // this is my Server IP
WiFiClient client;
IPAddress ipDevice;
IPAddress ipGateway;
IPAddress ipSubnet;
void setup()
{
pinMode(inputSig, INPUT);
digitalWrite(inputSig, LOW);
pinMode(inputSig2, INPUT);
digitalWrite(inputSig2, LOW);
}
bool checkAndConnect()
{
if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
int wifiCount = 0;
while(WiFi.status() != WL_CONNECTED){
delay(10);
}
delay(10);
ipDevice = WiFi.localIP();
ipGateway = WiFi.gatewayIP();
ipSubnet = WiFi.subnetMask();
delay(10);
return true;
}
return false;
}
void loop() {
checkAndConnect();
if (inputSig == HIGH) //check pin state on 11
{
PostFormData();
}
else if (inputSig2 == HIGH) // check pin state 10
{
PostFormData2();
}
delay(5000);
}
void PostFormData(){
String location = "/1/pm3/cgi/admin.cgi"; //location of the CGI script
String cmd = "POST " + location + " HTTP/1.1\r\n"; // complete HTTP request
cmd += "Host: shot.fm\r\n\r\n";
cmd += "action=messanger"; //Typo? should this be messenger instead?
cmd += "&from=admin";
cmd += "&subject=Gunshot_Detection";
cmd += "&by=email";
cmd += "&body=%26%2337%26%2337firstname%26%2337%26%2337%20Go%20to%20%26%2337%26%2337homepage%26%2337%26%2337%20to%20see%20Map%20for%20shooter%20location.%20Weapon%3A%20Gunshot%20Sensor%20Detection%20is%20detected%20at%0A%26%2337%26%2337streetaddress%26%2337%26%2337%20%26%2337%26%2337city%26%2337%26%2337%20%26%2337%26%2337State%26%2337%26%2337%26%2337%26%2337quote%26%2337%26%2337%20call%20%26%2337%26%2337tel%26%2337%26%2337%20now%20for%20more%20info.%20%20Click%20here%20to%20open%20Camera.%20%5B%20http%3A%2F%2Fshot.fm%2F1%2Fpm3%2Fcam.html%20%5D(http%3A%2F%2Fshot.fm%2F1%2Fpm3%2Fcam.html%20)";
IPAddress ip(72,167,183,14);
yield();
if(client.connect(ip, 80)){
client.println(cmd);
delay(10);
client.flush();
client.stop();
}
}
void PostFormData2(){
String location = "/1/pm3/cgi/admin.cgi";
String cmd = "POST " + location + " HTTP/1.1\r\n"; // complete HTTP request
cmd += "Host: shot.fm\r\n\r\n";
cmd += "action=messanger"; //Typo? should this be messenger instead?
cmd += "&from=admin";
cmd += "&subject=Gunshot_Detection";
cmd += "&by=email";
cmd += "&body=%26%2337%26%2337firstname%26%2337%26%2337%20Go%20to%20%26%2337%26%2337homepage%26%2337%26%2337%20to%20see%20Map%20for%20shooter%20location.%20Weapon%3A%20Gunshot%20Sensor%20Detection%20is%20detected%20at%0A%26%2337%26%2337streetaddress%26%2337%26%2337%20%26%2337%26%2337city%26%2337%26%2337%20%26%2337%26%2337State%26%2337%26%2337%26%2337%26%2337quote%26%2337%26%2337%20call%20%26%2337%26%2337tel%26%2337%26%2337%20now%20for%20more%20info.%20%20Click%20here%20to%20open%20Camera.%20%5B%20http%3A%2F%2Fshot.fm%2F1%2Fpm3%2Fcam.html%20%5D(http%3A%2F%2Fshot.fm%2F1%2Fpm3%2Fcam.html%20)";
IPAddress ip(72,167,183,14);
yield();
if(client.connect(ip, 80)){
client.println(cmd);
delay(10);
client.flush();
client.stop();
}
}
Any Ideas?