Proszę kod ostatecznie działający.
Polecam kartę VirginMobile - za 3 zł 300MB bez limitu wygaśnięcia konta. Mam taką w zegarku GPS dzieciaka i nie pamiętam kiedy ją załadowałem 15 zetami. Chyba z pół roku temu i dalej jest 10 zł.
Kod:
Kod: Zaznacz cały
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <DoubleResetDetector.h> //Bilioteka by Stephen Denne
#include <SoftwareSerial.h>
#include <Wire.h>
// Number of seconds after reset during which a
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 5
// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
SoftwareSerial mySerial(4, 5); // RX, TX Pins
String apn = "virgin-internet"; //APN
DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS);
//********************************************************PARAMETRY KONFIGURACYJNE****************************************************************
const unsigned Czas_max_timeout = 60000; //Czas TIMEOUT szukania WIFI w milisekundach = 10 sekund
const byte debug = 1; //1 = Włączone debugowanie, 0 = Wyłączone
//************************************************************************************************************************************************
byte gsm_mode = 0;
void setup()
{
if (debug == 1){
Serial.begin(9600);
Serial.println();
mySerial.begin(9600);
delay(100);
}
if (drd.detectDoubleReset()) {
gsm_mode = 2;
} else {
gsm_mode = 1;
}
for (int i=0; i <= 1000; i++){
delay(1);
drd.loop();
if (i == 500){
}
}
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
// You can also call drd.stop() when you wish to no longer
// consider the next reset as a double reset.
drd.stop();
}
void runsl() {
while (mySerial.available()) {
Serial.write(mySerial.read());
}
}
void loop()
{
mySerial.begin(9600);
delay(100);
if (debug == 1){
Serial.print("GSM mode = ");
Serial.println(gsm_mode);
}
for (unsigned timeout=0; timeout <= Czas_max_timeout; timeout++){
if (WiFi.status()){
delay(1);
}
else
{
timeout = Czas_max_timeout;
if (debug == 1){
Serial.println("Polaczono z WIFI");
}
}
}
if (gsm_mode == 1){
mySerial.println("AT");
runsl();//Print GSM Status an the Serial Output;
delay(1000);
mySerial.println("AT+SAPBR=3,1,Contype,GPRS");
runsl();
delay(1000);
mySerial.println("AT+SAPBR=3,1,APN," + apn);
runsl();
delay(100);
mySerial.println("AT+SAPBR =1,1");
runsl();
delay(1000);
mySerial.println("AT+HTTPINIT");
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =CID,1");
runsl();
delay(100);
mySerial.println("AT+HTTPSSL =1");
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =URL,https://svr5.supla.org/direct/134/mGYG2dsfZ/turn-on"); / tu wpisujecie wasz link po 1 krotnym wciśnięciu button
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =REDIR,1");
runsl();
delay(100);
mySerial.println("AT+HTTPACTION =2");
runsl();
delay(10000);
mySerial.println("AT+HTTPTERM");
runsl();
delay(1000);
mySerial.println("AT+SAPBR =0,1");
runsl();
delay(2000);
mySerial.println("AT+CSCLK=2");
runsl();
delay(200);
mySerial.println("AT+CSCLK?");
runsl();
delay(200);
}
if (gsm_mode == 2){
mySerial.println("AT");
runsl();//Print GSM Status an the Serial Output;
delay(1000);
mySerial.println("AT+SAPBR=3,1,Contype,GPRS");
runsl();
delay(1000);
mySerial.println("AT+SAPBR=3,1,APN," + apn);
runsl();
delay(100);
mySerial.println("AT+SAPBR =1,1");
runsl();
delay(1000);
mySerial.println("AT+HTTPINIT");
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =CID,1");
runsl();
delay(100); :)
mySerial.println("AT+HTTPSSL =1");
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =URL,https://svr5.supla.org/direct/134/mGYG2Qsdfsd/turn-off"); // tu wpisujecie wasz link po 2 krotnym wciśnięciu button
runsl();
delay(100);
mySerial.println("AT+HTTPPARA =REDIR,1");
runsl();
delay(100);
mySerial.println("AT+HTTPACTION =2");
runsl();
delay(10000);
mySerial.println("AT+HTTPTERM");
runsl();
delay(1000);
mySerial.println("AT+SAPBR =0,1");
runsl();
delay(2000);
mySerial.println("AT+CSCLK=2");
runsl();
delay(200);
mySerial.println("AT+CSCLK?");
runsl();
delay(200);
}
if (debug == 1){
Serial.println("Koniec polaczenia");
}
WiFi.disconnect();
if (debug == 1){
Serial.print("Dobranoc");
}
ESP.deepSleep(0);
}
Mam też wersję pod ARDUINO NANO jak by ktoś chciał. Ale musicie sobie skompilować . Na razie nie potrafię zrobić do tego managera (a'la manager połączenia z 192.168.1.4 , )który by wpisywał linki
jak coś nie działa to włącz zasilanie.....