<commit_before>#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <DHT.h>
#include "FS.h"

//device serial number
const char* serialNo = "0123a";
// gps 
static const int RXPin = 5, TXPin = 4;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// dht pin 
int dhtSensorPin = 2 ;
//initialize dht sensor
DHT dht(dhtSensorPin, DHT11);

// not sure yet where the server will be hosted
String url = "/api/v1/devices/reports";

StaticJsonBuffer<500> JSONbuffer;   
JsonObject& root = JSONbuffer.createObject(); 
JsonArray& values = root.createNestedArray("incidentValues");
JsonObject& temp = values.createNestedObject();
JsonObject& humd = values.createNestedObject();
 
void setup() {
  Serial.begin(9600);
  // mounting the filesystem
  bool result = SPIFFS.begin();
  Serial.println("SPIFFS opened: " + result);
  // remove the file if it exists
  SPIFFS.remove("/reports.txt");
  ss.begin(GPSBaud);
  temp["metric"] = "Temperature";
  humd["metric"] = "Humidity";
  dht.begin();                         
  WiFi.begin("your ssid", "pass");    
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Waiting for connection");
  }
   Serial.println("connected");
}

void loop() {
	while (ss.available() > 0)
	if (gps.encode(ss.read())) { 
		if ( gps.date.isValid() && gps.time.isValid()) { 
			if (checkIfStartedTrip() == true)
			sendInfo();
		}
	}
}

boolean checkIfStartedTrip() {
	char path[50] = "/api/v1/devices/currentTrip/";
	strncpy(path, serialNo, 6);
	HTTPClient http;
	http.begin(path);
	http.sendRequest("GET");
	String payload = http.getString();
	Serial.println(payload);    
	delay(1000);
}


void httpPost(JsonObject& json) {
  HTTPClient http;
  http.begin(url);
  char JSONmessageBuffer[300];
  json.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
  Serial.println(JSONmessageBuffer);
  http.addHeader("Content-Type", "application/json");<commit_msg>Update esp.ino<commit_after>#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <DHT.h>
#include "FS.h"

//device serial number
const char* serialNo = "0123a";
// gps 
static const int RXPin = 5, TXPin = 4;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// dht pin 
int dhtSensorPin = 2 ;
//initialize dht sensor
DHT dht(dhtSensorPin, DHT11);

// not sure yet where the server will be hosted
String url = "/api/v1/devices/reports";

StaticJsonBuffer<500> JSONbuffer;   
JsonObject& root = JSONbuffer.createObject(); 
JsonArray& values = root.createNestedArray("incidentValues");
JsonObject& temp = values.createNestedObject();
JsonObject& humd = values.createNestedObject();
 
void setup() {
  Serial.begin(9600);
  // mounting the filesystem
  bool result = SPIFFS.begin();
  Serial.println("SPIFFS opened: " + result);
  // remove the file if it exists
  SPIFFS.remove("/reports.txt");
  ss.begin(GPSBaud);
  temp["metric"] = "Temperature";
  humd["metric"] = "Humidity";
  dht.begin();                         
  WiFi.begin("your ssid", "pass");    
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Waiting for connection");
  }
   Serial.println("connected");
}

void loop() {
	while (ss.available() > 0)
	if (gps.encode(ss.read())) { 
		if ( gps.date.isValid() && gps.time.isValid()) { 
			if (checkIfStartedTrip() == true)
			sendInfo();
		}
		delay(1000);
	}
}

boolean checkIfStartedTrip() {
	char path[100] = "/api/v1/devices/currentTrip/";
	strcat(path, serialNo);
	HTTPClient http;
	http.begin(path);
	http.sendRequest("GET");
	String payload = http.getString();
	Serial.println(payload);    
	if (payload == "true") {
		return true;
	}
	return false;
}


void httpPost(JsonObject& json) {
  HTTPClient http;
  http.begin(url);
  char JSONmessageBuffer[300];
  json.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
  Serial.println(JSONmessageBuffer);
  http.addHeader("Content-Type", "application/json");
{'fraction_non_alphanumeric': 0.15192850423330198, 'fraction_numerical': 0.021636876763875823, 'mean_word_length': 4.250617283950617, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693155', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1481, 'n_words': 338}