วันอังคารที่ 30 ตุลาคม พ.ศ. 2561

ESP8266 + GPS + Realtime tracking +HTML+No need app





MAP I/O




Wiring

                Node MCU  >>  GPS 

           D1 (GPIO 5)    >>   RX
           D2 (GPIO 4)    >>   TX
           3V                    >>   VCC
           GND                >>   GND






GPS(Global Positioning system )


Image result for gps theory



NMEA(National Marine Electronics Association) structure 

$GPRMC,162254.00,A,3723.02837,N,12159.39853,W,0.820,188.36,110706,,,A*74
$GPVTG,188.36,T,,M,0.820,N,1.519,K,A*3F
$GPGGA,162254.00,3723.02837,N,12159.39853,W,1,03,2.36,525.6,M,-25.6,M,,*65
$GPGSA,A,2,25,01,22,,,,,,,,,,2.56,2.36,1.00*02
$GPGSV,4,1,14,25,15,175,30,14,80,041,,19,38,259,14,01,52,223,18*76
$GPGSV,4,2,14,18,16,079,,11,19,312,,14,80,041,,21,04,135,25*7D
$GPGSV,4,3,14,15,27,134,18,03,25,222,,22,51,057,16,09,07,036,*79
$GPGSV,4,4,14,07,01,181,,15,25,135,*76
$GPGLL,3723.02837,N,12159.39853,W,162254.00,A,A*7C
$GPZDA,162254.00,11,07,2006,00,00*63

In this  project We need only coordinate then We need only "$GPGGA"

$GPGGA,162254.00,3723.02837,N,12159.39853,W,1,03,2.36,525.6,M,-25.6,M,,*65

GGA - essential fix data which provide 3D location and accuracy data.
 $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47

Where:
     GGA          Global Positioning System Fix Data
     123519       Fix taken at 12:35:19 UTC
     4807.038,N   Latitude 48 deg 07.038' N
     01131.000,E  Longitude 11 deg 31.000' E
     1            Fix quality: 0 = invalid
                               1 = GPS fix (SPS)
                               2 = DGPS fix
                               3 = PPS fix
          4 = Real Time Kinematic
          5 = Float RTK
                               6 = estimated (dead reckoning) (2.3 feature)
          7 = Manual input mode
          8 = Simulation mode
     08           Number of satellites being tracked
     0.9          Horizontal dilution of position
     545.4,M      Altitude, Meters, above mean sea level
     46.9,M       Height of geoid (mean sea level) above WGS84
                      ellipsoid
     (empty field) time in seconds since last DGPS update
     (empty field) DGPS station ID number
     *47          the checksum data, always begins with *
If the height of geoid is missing then the altitude should be suspect. Some non-standard implementations report altitude with respect to the ellipsoid rather than geoid altitude. Some units do not report negative altitudes at all. This is the only sentence that reports altitude.










                             GPS module : https://goo.gl/UbMufK

GPS Module Banggood : https://goo.gl/2JmreQ

ESP8266 NodeMCU : https://goo.gl/7MoawN

ESP8266 NodeMCU Banggood : https://goo.gl/cBFyZ3





Please Donate for long life blog
ขอเชิญร่วมบริจาค เพื่อสนับสนุนทุนการทำโครงงานต่อไป



CODE

#include <SoftwareSerial.h>

#include <TinyGPS++.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>

TinyGPSPlus gps;

SoftwareSerial ss(4,5); // for connect GPS

const char* ssid = "santi";
const char* password = "santi12345678";

float latitude , longitude;

int year,month,date,hour,minute,second;
String date_str,time_str,lat_str,lng_str;

int pm;

WiFiServer server(80);

void setup()
{
  Serial.begin(115200);
  ss.begin(9600);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid,password);

  while(WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi Connected");

  server.begin();
  Serial.println("Start Started");

  //Show IP address

  Serial.println(WiFi.localIP());

}

void loop()

{
  while (ss.available()>0)
  if(gps.encode(ss.read()))
  {
    if(gps.location.isValid())
    {
      latitude = gps.location.lat();
      lat_str = String(latitude , 6);
      longitude = gps.location.lng();
      lng_str = String(longitude , 6);

    }

    if(gps.date.isValid())

    {
      date_str = "";
      date = gps.date.day();
      month = gps.date.month();
      year = gps.date.year();

      if(date<10)
      date_str = '0';
      date_str += String(date);

      date_str += "/";

      if(month < 10)
      date_str += '0';
      date_str += String(month);

      date_str += "/";

      if(year<10)
      date_str += '0';
      date_str += String(year);
    }

    if(gps.time.isValid())
    {
      time_str = "";
      hour = gps.time.hour();
      minute = gps.time.minute();
      second = gps.time.second();

      minute = (minute + 30);
      if(minute>59)
      {
        minute = minute - 60;
        hour = hour + 1;
      }
      hour = (hour + 5);
      if (hour > 23)
      hour = hour - 24;

      if(hour>= 12)
      pm = 1;

      else 

      pm = 0;

      hour = hour % 12;

      if(hour < 10)
     time_str ='0';
     time_str += String(hour);

     time_str += ":";

     if(minute<10)
     time_str ='0';
     time_str += String(minute);

     time_str += ":";

     if(second<10)
     time_str ='0';
     time_str += String(second);

     if (pm == 1)
     time_str += "PM";
     else
     time_str += "AM";

    }

  }

  // Check if a client has connected 

  WiFiClient client = server.available();
  if(!client)
  {
    return;

  }

  //prepare the response

  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n <!DOCTYPE html><html><head><title>GPSNodeMCU A-Arduino </title><style>";
  s += "a:link {background-color: YELLOW;text-decoration: none;}";
  s += "table,th,td {border: 1px solid black;}</style></head><body><h1 style=";
  s += "font-size:300%;";
  s += " ALIGN=CENTER> GPS Interfacing with NodeMCU</h1>";
  s += "<p ALIGN=CENTER style=""font-size:150%;""";  
  s += "> <b>Location Details</b></p><table ALIGN=CENTER style=";
  s += "width:50%";
  s += "> <tr> <th>Latitude</th>";
  s += "<td ALIGN=CENTER>";
  s += lat_str;
  s += "</td></tr><tr><th>Longitude</th><td ALIGN=CENTER>";
  s += lng_str;
  s += "</td></tr><tr><th>Date</th><td ALIGN=CENTER>";
  s += date_str;
  s += "</td></tr><tr><th>Time</th><td ALIGN=CENTER>";
  s += time_str;
  s += "</td></tr></table>";

  if(gps.location.isValid())
  {
   s += "<a href=\"http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
   s += lat_str;
   s += '+';
   s += lng_str;
   s += "\">Click here!To check the location in Google maps.</a>";
  }

   s += "</body> </html> \n";

  client.print(s);
  delay(100);
  
   
        
      
      }
  

วันอาทิตย์ที่ 21 ตุลาคม พ.ศ. 2561

ESP8266 web server Home IOT




ESP8266 


Use CH340G repalce the CP2102.
Open-source, Interactive, Programmable, Low cost, Simple, Smart, WI-FI enabled
FOR Arduino like hardware IO
Advanced API for hardware IO, which can dramatically reduce the redundant work for configuring and manipulating hardware.
Code like FOR arduino, but interactively in Lua script.
Nodejs style network API
Event-driven API for network applicaitons,
which faciliates developers writing code running on a 5mm*5mm sized MCU in Nodejs style.
Greatly speed up your IOT application developing process.
Lowest cost WI-FI
Less than $3 WI-FI MCU ESP8266 integrated and esay to prototyping development kit.
We provide the best platform for IOT application development at the lowest cost.
ขั้นตอนการลงโปรแกรม และ ติดตั้ง
1.        โหลดIDE เวอร์ชั่น 1.6.5 ถ้าตัวอื่นก็ลองดูได้ครับผมใช้ตัวนี้ โหลดจาก   https://www.arduino.cc/en/Main/Software

เลื่อนลงมาอีกนิดจะมีให้เลือกเวอร์ชั่น
Previous Release

การติดตั้ง Board ESP8266IDE Sketch ที่แนะนำคือ เวอร์ชั่น 1.6.5



File >Preferences>


http://arduino.esp8266.com/stable/package_esp8266com_index.json






ขั้นตอนการตรวจสอบว่าบอร์ดติดตั้งหรือยัง



MAP I/O




ต่อวงจรสำหรับ โรเจคนี้




Please Donate for long life blog
ขอเชิญร่วมบริจาค เพื่อสนับสนุนทุนการทำโครงงานต่อไป



Code

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

// Replace with your network credentials
const char* ssid = "santi";
const char* password = "santi12345678";

ESP8266WebServer server(80);

String webPage = "";

Int  gpio16_pin = D0;  
int  gpio5_pin = D1;
int  gpio4_pin = D2;
int  gpio0_pin = D3;
void setup(void){
  webPage += "<h1>A-Arduino Farm</h1><p>pump#1 <a href=\"socket1On\"><button>ON</button></a>&nbsp;<a href=\"socket1Off\"><button>OFF</button></a></p>";
  webPage += "<p>Pump#2 <a href=\"socket2On\"><button>ON</button></a>&nbsp;<a href=\"socket2Off\"><button>OFF</button></a></p>";
  webPage += "<p>Pump#3 <a href=\"socket3On\"><button>ON</button></a>&nbsp;<a href=\"socket3Off\"><button>OFF</button></a></p>";
  webPage += "<p>Pump#4 <a href=\"socket4On\"><button>ON</button></a>&nbsp;<a href=\"socket4Off\"><button>OFF</button></a></p>";
 
  // preparing GPIOs
  pinMode(gpio16_pin, OUTPUT);
  digitalWrite(gpio16_pin, HIGH);
 
  pinMode(gpio5_pin, OUTPUT);
  digitalWrite(gpio5_pin, HIGH);

  pinMode(gpio4_pin, OUTPUT);
  digitalWrite(gpio4_pin, HIGH);

  pinMode(gpio0_pin, OUTPUT);
  digitalWrite(gpio0_pin, HIGH);
 
  delay(1000);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
 
  server.on("/", [](){
    server.send(200, "text/html", webPage);
  });
  server.on("/socket1On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio16_pin, LOW);
    delay(1000);
  });
  server.on("/socket1Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio16_pin, HIGH);
    delay(1000);
  });
  server.on("/socket2On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio5_pin, LOW);
    delay(1000);
  });
  server.on("/socket2Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio5_pin, HIGH);
    delay(1000);
  });


//////////////////////

server.on("/socket3On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio4_pin, LOW);
    delay(1000);
  });
  server.on("/socket3Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio4_pin, HIGH);
    delay(1000);
  });
  server.on("/socket4On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio0_pin, LOW);
    delay(1000);
  });
  server.on("/socket4Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio0_pin, HIGH);
    delay(1000);
  });

 
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}































วันพุธที่ 12 กันยายน พ.ศ. 2561

GSM sim808 GSM / GPS /GPRS show real location using AT command.

aeProduct.getSubject()

aeProduct.getSubject()
aeProduct.getSubject()



Code


#include <SoftwareSerial.h>
SoftwareSerial sim808(7,8);

char phone_no[] = "084xxxxxx"; // replace with your phone no.
String data[5];
#define DEBUG true
String state,timegps,latitude,longitude;

void setup() {
 sim808.begin(9600);
 Serial.begin(9600);
 delay(50);

 sim808.print("AT+CSMP=17,167,0,0");  // set this parameter if empty SMS received
 delay(100);
 sim808.print("AT+CMGF=1\r"); 
 delay(400);

 sendData("AT+CGNSPWR=1",1000,DEBUG);
 delay(50);
 sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
 delay(150);

}

void loop() {
  sendTabData("AT+CGNSINF",1000,DEBUG);
  if (state !=0) {
    Serial.println("State  :"+state);
    Serial.println("Time  :"+timegps);
    Serial.println("Latitude  :"+latitude);
    Serial.println("Longitude  :"+longitude);

    sim808.print("AT+CMGS=\"");
    sim808.print(phone_no);
    sim808.println("\"");
    
    delay(300);

    sim808.print("http://maps.google.com/maps?q=loc:");
    sim808.print(latitude);
    sim808.print(",");
    sim808.print (longitude);
    delay(200);
    sim808.println((char)26); // End AT command with a ^Z, ASCII code 26
    delay(200);
    sim808.println();
    delay(20000);
    sim808.flush();
    
  } else {
    Serial.println("GPS Initialising...");
  }
}

void sendTabData(String command , const int timeout , boolean debug){

  sim808.println(command);
  long int time = millis();
  int i = 0;

  while((time+timeout) > millis()){
    while(sim808.available()){
      char c = sim808.read();
      if (c != ',') {
         data[i] +=c;
         delay(100);
      } else {
        i++;  
      }
      if (i == 5) {
        delay(100);
        goto exitL;
      }
    }
  }exitL:
  if (debug) {
    state = data[1];
    timegps = data[2];
    latitude = data[3];
    longitude =data[4];  
  }
}
String sendData (String command , const int timeout ,boolean debug){
  String response = "";
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while ( (time+timeout ) > millis()){
    while (sim808.available()){
      char c = sim808.read();
      response +=c;
    }
  }
  if (debug) {
     Serial.print(response);
     }
     return response;
}




วันพฤหัสบดีที่ 23 สิงหาคม พ.ศ. 2561

GSM sim 900 Learn AT command made Flooding and Raining Alert



คลิ้กดูรายละเอียดครับ

รายละเอียด New SIM900A V4.0 Kit Wireless Extension Module GSM GPRS Board Antenna Tested Worldwide Store - intl

  • 100% brand new
  • High quality & professional
Features:
The onboard two set power supply interface VCC5 5V power supply, VCC4 interface, 3.5--4.5V power supply, optional power on self starting (default) and control start.
The onboard SMA (default) and IPXmini antenna interface, SIM900A interface reserved reset.
The size of the module is 49*50, all the new and original device.
The computer can give early computer debugging USB module power supply, a very large amount of data under the condition of the recommended current more than 1A. Standby dozens of MA data can be set to provide dormancy, dormancy of 10MA low power. Support 2, mobile phone 3,4G card.
The serial port circuit: support for 3.3V single chip microcomputer. TTL serial port support
3.3 and 5V single chip microcomputer.
The SIM card circuit to increase the SMF05C ESD chip.
Antenna circuit: guarantee short and straight, so as to ensure the signal strength.
PCB display screen printing mark: each interface, convenient development two times, the SIM900/A hardware is completely follow the design when the design manual.
Two power supply interface: VCC5, 5V DC above 1A. Computer 5V power supply can be early computer USB. DC long data circuit over larger recommended 5V1A. VCC4, 3.5--4.5V power supply, ibid., suitable for lithium battery.
Control pin all leads.
A TTL level, compatible with 3.3V and 5V.
The two antenna interface, the default SMA straight head, connector for IPXmini antenna.
One way of speech interface, the way Mike interface.
The control interface of each pin description:
GND - GND
SIMR SIM900A RXD, TTL level, can not be directly connected to the 232 level
SIMT SIM900A TXD, TTL level, can not be directly connected to the 232 level
RST - SIM900A reset, active low
VCC_MCU when the SIM900A module and 5V TTL level communication, this pin is connected to DC 5V; when the level of communication of SIM900A and 3.3V TTL, this pin is connected to DC 3.3V.
VCC5----DC 5V input.
VCC4------DC3.5--4.5 input

Onboard Resources:
Serial port circuit(with protection)
Antenna interface circuit(SMA bend female port)
SIM card circuit(flip SIM slot)
4*3.5 fixture hole 4pcs
SIM900A serial port output terminal

Specifications:
Size:49mm x 47mm
Net Weight:28g
Weight: 38g


Wiring 



A TTL level, compatible with 3.3V and 5V.
The two antenna interface, the default SMA straight head, connector for IPXmini antenna.
One way of speech interface, the way Mike interface.
The control interface of each pin description:
GND - GND
SIMR SIM900A RXD, TTL level, can not be directly connected to the 232 level
SIMT SIM900A TXD, TTL level, can not be directly connected to the 232 level
RST - SIM900A reset, active low
VCC_MCU when the SIM900A module and 5V TTL level communication, this pin is connected to DC 5V; when the level of communication of SIM900A and 3.3V TTL, this pin is connected to DC 3.3V.
VCC5----DC 5V input.
VCC4------DC3.5--4.5 input

Green wire : RX
Gray wire   : TX




 External power  supply





RX,TX  connect to 2,3 

External power supply 5 volt

///////////////////////////////////AT command\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Link here is AT command  document 👇👇



****************CODE****************

Test send message using AT command  


#include <SoftwareSerial.h>
SoftwareSerial sim900a(7, 8); // 7=RX, 8=TX  // GSM TX SHOULD CONNECT TO 2, GSM RX SHOULD CONNECT TO 3


void setup() {
  Serial.begin(9600);
sim900a.begin(9600);
}
void loop()
{
  delay(1000);
  send_test_sms();// SEND TEST SMS

  
}
void send_test_sms()
{
sim900a.print("AT\r");// 
delay(500);
sim900a.print("AT+CMGF=1;\r");       // select message mode
delay(500);
sim900a.print("AT+CMGS=\"0843545xxx\";\r");            // ENTER YOUR RECEIVER PHONE NO 
delay(500);
sim900a.print("I AM GSM AND SENDING SMS TEST SMS");// message data , you can send variables , strings or any kind of other data 

sim900a.print("\r");
    delay(1000);
sim900a.println((char)26);

sim900a.write(0x1a);// CTRL+Z SENDING CODE CTRL+Z=0x26
}



😃😃😃😃😃😃😃😃😃😃Add sensor 😃😃😃😃😃😃😃😃





#include <SoftwareSerial.h>

SoftwareSerial sim900a(7, 8); // 7=RX, 8=TX  // GSM TX SHOULD CONNECT TO 7, 

GSM RX SHOULD CONNECT TO 8

//   wet sensor para

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)


///////////////////////////////////////////////////

void setup() {
  Serial.begin(9600);
sim900a.begin(9600);



}
void loop()
{
  delay(1000);
  send_test_sms();// SEND TEST SMS
//WetSensor();
  
}
void send_test_sms()
{
sim900a.print("AT\r");// 
delay(500);
sim900a.print("AT+CMGF=1;\r");// select message mode
delay(500);
sim900a.print("AT+CMGS=\"your phone no. \";\r");// RECEIVER PHONE NO HERE

delay(500);

// read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(100);

if(sensorValue < 500)  //  

{

sim900a.print("Flooding warnign !!! ");

sim900a.print("\r");
    delay(1000);
sim900a.println((char)26);

sim900a.write(0x1a);// CTRL+Z SENDING CODE CTRL+Z=0x26
}

}