├── .gitattributes └── 4g_gps_tracker └── 4g_gps_tracker.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /4g_gps_tracker/4g_gps_tracker.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * This is the code for the Project 4 | * 5 | * 4G GPS Tracker using All new Blynk 2.0 6 | * It's full tutorial is uploaded on our YouTube channel 7 | * https://www.youtube.com/techiesms 8 | * 9 | * 10 | * Code written by Dhruv Soni for techiesms on 02/07/22 11 | * 12 | * 13 | * 14 | */ 15 | 16 | 17 | 18 | #include 19 | #include 20 | 21 | 22 | #define DEBUG true 23 | #define MODE_1A 24 | 25 | #define DTR_PIN 9 26 | #define RI_PIN 8 27 | 28 | #define LTE_PWRKEY_PIN 5 29 | #define LTE_RESET_PIN 6 30 | #define LTE_FLIGHT_PIN 7 31 | 32 | String token = "ADD YOU TOKEN HERE"; 33 | String from_usb = ""; 34 | String loc = ""; 35 | String longitude = ""; 36 | String lattitude = ""; 37 | 38 | //FUNCTION TO PASS AT COMMAND 39 | 40 | String sendData(String command, const int timeout, boolean debug) 41 | { 42 | String response = ""; 43 | Serial1.println(command); 44 | 45 | long int time = millis(); 46 | while ( (time + timeout) > millis()) 47 | { 48 | while (Serial1.available()) 49 | { 50 | char c = Serial1.read(); 51 | response += c; 52 | } 53 | } 54 | if (debug) 55 | { 56 | SerialUSB.print(response); 57 | } 58 | return response; 59 | } 60 | 61 | //FUNCTION TO CHECK SIGNAL STRENGTH 62 | 63 | int check_signal(void) 64 | { 65 | while(1) 66 | { 67 | String sig = sendData("AT+CSQ",3000,DEBUG); 68 | int i=0; 69 | String strength; 70 | while(sig[i]!=':')i++; 71 | 72 | String loc_2 = sig.substring(i+2); 73 | 74 | i=0; 75 | while(loc_2[i]!=',')i++; 76 | 77 | strength = loc_2.substring(0,i); 78 | 79 | int strength_1 = strength.toInt(); 80 | SerialUSB.println(strength_1); 81 | 82 | return strength_1; 83 | } 84 | } 85 | 86 | //FUNCTION TO GET LATITUDE AND LONGITUDE STRING 87 | 88 | void gpsLocation(String local) 89 | { 90 | // char* loc_2 = local; 91 | // int p=0; 92 | 93 | while(1) 94 | { 95 | int i=0; 96 | while(local[i]!=':')i++; 97 | 98 | String loc_2 = local.substring(i+2); 99 | 100 | i=0; 101 | while(loc_2[i]!=',')i++; 102 | 103 | lattitude = loc_2.substring(0,i); 104 | SerialUSB.println(lattitude); 105 | 106 | int j = i+3; 107 | int k = j; 108 | 109 | while(loc_2[k]!=',')k++; 110 | 111 | longitude = loc_2.substring(j,k); 112 | SerialUSB.println(longitude); 113 | 114 | return; 115 | 116 | } 117 | } 118 | 119 | //CONVERSION OF GIVEN LATTITUDE FORMAT FROM NMEA TO PARSER 120 | 121 | String conversion(String local) 122 | { 123 | if(local[0]=='0'){ 124 | String str_end = local.substring(3); 125 | 126 | String str_init = local.substring(1,3); 127 | 128 | int val = str_init.toInt(); 129 | 130 | double deci_val = str_end.toDouble() ; 131 | 132 | double new_value = val+(deci_val / 60); 133 | SerialUSB.println(new_value); 134 | 135 | String final_val = String(new_value,5); 136 | 137 | return final_val; 138 | } 139 | else if(local[0]!='0') 140 | { 141 | String str_end = local.substring(2); 142 | 143 | String str_init = local.substring(0,2); 144 | 145 | int val = str_init.toInt(); 146 | 147 | double deci_val = str_end.toDouble() ; 148 | 149 | double new_value = val+(deci_val / 60); 150 | SerialUSB.println(new_value); 151 | 152 | String final_val = String(new_value,5); 153 | 154 | return final_val; 155 | } 156 | } 157 | 158 | //FUNCTION TO PASS LOCATION IN BLYNK API 159 | 160 | void map_loc(String lat1,String lon1) 161 | { 162 | String lat = conversion(lat1); 163 | String lon = conversion(lon1); 164 | 165 | SerialUSB.print("lattitude = ");SerialUSB.println(lat); 166 | SerialUSB.print("longitude = ");SerialUSB.println(lon); 167 | 168 | String http_str = "AT+HTTPPARA=\"URL\",\"https://blr1.blynk.cloud/external/api/batch/update?token=" + token + "&V9=" + lon + "&V9=" + lat + "\"\r\n"; 169 | SerialUSB.println(http_str); 170 | sendData("AT+HTTPINIT\r\n", 3000, DEBUG); 171 | sendData(http_str, 3000, DEBUG); 172 | sendData("AT+HTTPACTION=0\r\n", 3000, DEBUG); 173 | sendData("AT+HTTPTERM\r\n", 3000, DEBUG); 174 | } 175 | 176 | void setup(){ 177 | SerialUSB.begin(115200); 178 | //while (!SerialUSB) 179 | // { 180 | ; // wait for Arduino serial Monitor port to connect 181 | // } 182 | 183 | delay(100); 184 | 185 | Serial1.begin(115200); 186 | 187 | //INITIALIZING GSM MODULE 188 | 189 | pinMode(LTE_RESET_PIN, OUTPUT); 190 | digitalWrite(LTE_RESET_PIN, LOW); 191 | 192 | pinMode(LTE_PWRKEY_PIN, OUTPUT); 193 | digitalWrite(LTE_RESET_PIN, LOW); 194 | delay(100); 195 | digitalWrite(LTE_PWRKEY_PIN, HIGH); 196 | delay(2000); 197 | digitalWrite(LTE_PWRKEY_PIN, LOW); 198 | 199 | pinMode(LTE_FLIGHT_PIN, OUTPUT); 200 | digitalWrite(LTE_FLIGHT_PIN, LOW); //Normal Mode 201 | // digitalWrite(LTE_FLIGHT_PIN, HIGH);//Flight Mode 202 | 203 | SerialUSB.println("Maduino Zero 4G Test Start!"); 204 | 205 | 206 | 207 | SerialUSB.println(sendData("AT+CGMM\r\n", 3000, DEBUG)); 208 | sendData("AT+CPIN?\r\n",3000,DEBUG); 209 | 210 | sendData("AT+COPS?\r\n",3000,DEBUG); 211 | 212 | sendData("AT+CNUM\r\n",3000,DEBUG); 213 | 214 | //INITIALIZING GPS MODULE 215 | 216 | sendData("AT+CGPS=1",3000,DEBUG); 217 | delay(60000); 218 | 219 | 220 | } 221 | 222 | void loop(){ 223 | 224 | //CHECKING SIGNAL STRENGTH 225 | 226 | if(check_signal()>=10) 227 | { 228 | loc = sendData("AT+CGPSINFO\r\n",3000,DEBUG); 229 | gpsLocation(loc); 230 | if(lattitude!=""&& longitude!="") 231 | { 232 | map_loc(lattitude,longitude); 233 | } 234 | delay(5000); 235 | } 236 | } 237 | --------------------------------------------------------------------------------