1010#define WIEGAND_DATA_0 D3 // Wiegand line pins
1111#define WIEGAND_DATA_1 D4 \
1212#define MAX_CODES 100 // Maximum number of codes to store
13+ // Define the pins used for the GPS module
14+ const int gpsRxPin = 8 ; // GPS module TX pin to Node MCU D8 pin
15+ const int gpsTxPin = 7 ; // GPS module RX pin to Node MCU D7 pin
16+
17+ // Create a SoftwareSerial object for the GPS module
18+ SoftwareSerial gpSS (gpsRxPin, gpsTxPin);
1319
1420static const uint32_t BaudRate = 9600 ;
1521
@@ -21,9 +27,6 @@ WIEGAND wg;
2127
2228String serverName = " http://192.168.1.9:5001/api/v1/gps/product-item" ;
2329
24- // static const int RXPin = 5, TXPin = 6;
25- SoftwareSerial ss (5 , 6 ); // same as wiegand???
26-
2730
2831uint32_t codes[MAX_CODES ]; // Array to store previous codes
2932int num_codes = 0 ; // Number of codes currently stored
@@ -67,7 +70,7 @@ void setup() {
6770 wg.begin (WIEGAND_DATA_0 , WIEGAND_DATA_1 );
6871
6972 // after setting-up RFID reader, set-up GPS module
70- ss .begin (BaudRate); // for gps
73+ gpSS .begin (BaudRate); // for gps
7174}
7275
7376void loop () {
@@ -143,4 +146,42 @@ void loop() {
143146 Serial.println (" WiFi Disconnected" );
144147 }
145148 }
149+
150+ // For GPS
151+ if (gpSS.available () > 0 ) {
152+ char c = gpSS.read (); // while acquiring signal, read the incoming byte
153+
154+ static char buffer[80 ];
155+ static int i = 0 ;
156+ buffer[i++] = c; // generating string
157+ bool end_of_string = c == ' \n ' ;
158+ if (end_of_string) {
159+ WiFiClient client;
160+ HTTPClient http;
161+
162+ // Your Domain name with URL path or IP address with path
163+ http.begin (client, serverName);
164+
165+ // If you need Node-RED/server authentication, insert user and password below
166+ // http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
167+
168+ http.addHeader (" Content-Type" , " application/json" );
169+ int httpResponseCode = http.POST (" {\" longitude\" : 48.2082, \" latitude\" : 16.3738, \" productItemId\" : \" " + String (buffer) + " \" }" );
170+
171+
172+ if (httpResponseCode>0 ) {
173+ Serial.print (" HTTP Response code: " );
174+ Serial.println (httpResponseCode);
175+ String payload = http.getString ();
176+ Serial.println (payload);
177+ }
178+ else {
179+ Serial.print (" Error code: " );
180+ Serial.println (httpResponseCode);
181+ }
182+ // Free resources
183+ http.end ();
184+ // send_post_request("{\"longitude\": 48.2082, \"latitude\": 16.3738, \"productItemId\": \"" + String(buffer) + "\"}", "/api/v1/gps/product-item");
185+ }
186+ }
146187}
0 commit comments