NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"

//Kapadokya GSM Shield için pinler
#define FONA_RX 11
#define FONA_TX 10
#define FONA_RST 4
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

#define FONA_APN "internet"
#define FONA_USERNAME "vodafone"
#define FONA_PASSWORD "vodafone"
#define AIO_SERVER "37.148.209.175"
#define AIO_SERVERPORT 2023

Adafruit_MQTT_FONA mqtt(&fona, AIO_SERVER, AIO_SERVERPORT);
#define halt(s) { Serial.println(F( s )); while(1); }
boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password);

Adafruit_MQTT_Publish loc = Adafruit_MQTT_Publish(&mqtt, "LOCATION");
Adafruit_MQTT_Subscribe led = Adafruit_MQTT_Subscribe(&mqtt, "LED");

uint8_t txfailures = 0;
#define MAXTXFAILURES 3

#include <TinyGPS.h>
TinyGPS gps;
#define ss Serial1

void setup() {

ss.begin(9600);
Serial.begin(9600);
while (!Serial);
Serial.println(F("System started."));
mqtt.subscribe(&led);

while (! FONAconnect(F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD))) {
Serial.println("Retrying FONA");
}

Serial.println(F("Connected to Cellular!"));

}

uint32_t x = 0;

int tempc_kontrol[] = {1};

void loop() {
sensorDeger = analogRead(analogPin);
gerilimDeger = (sensorDeger/1023)*5000;
sicaklikDeger = gerilimDeger / 10.0;
tempc_kontrol[1] = sicaklikDeger;
while(ss.available() > 0){
if(gps.encode(ss.read())){
MQTT_connect();

float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
int alt = gps.f_altitude();
int spd = gps.f_speed_kmph();
int crs = gps.f_course();

String locData = String(flat, 6) + "," + String(flon, 6) + "," + String(alt) + "," + String(spd) + "," + String(crs) + "1" + "10001";
char locData2[100];
locData.toCharArray(locData2, 100);

Serial.print(F("nSending LOCATION val: ")); Serial.print(locData2); Serial.print(F("..."));

if (!loc.publish(locData2)) {
Serial.println(F("Failed"));
txfailures++;
} else {
Serial.println(F("OK!"));
txfailures = 0;
}
mqtt.disconnect();
if(tempc_kontrol[1] - tempc_kontrol[0] > 0.6 || tempc_kontrol[1] - tempc_kontrol[0] < -0.6){
tempc_kontrol[0] = tempc_kontrol[1];
String url = "http://gpsmqtt.tk/post-sensor-data.php?api_key=tPmAT5Ab3j7F9&longitude=" + String(flat) + "&latitude=" + String(flon) + "&temp=" + String(sicaklikDeger) + "&datte=0&clock=0&which_product_id=1&owner_id=10001";
gsm_send_serial("AT+HTTPINIT");
gsm_send_serial("AT+HTTPPARA=CID,1");
gsm_send_serial("AT+HTTPPARA=URL," + url);
gsm_send_serial("AT+HTTPACTION=0");
gsm_send_serial("AT+HTTPREAD");
gsm_send_serial("AT+HTTPTERM");
}
}
}


}

void gsm_send_serial(String command) {
Serial.println("Send ->: " + command);
fonaSS.println(command);
long wtimer = millis();
while (wtimer + 1000 > millis()) {
while (fonaSS.available()) {
Serial.write(fonaSS.read());
}
}
Serial.println();
}

void MQTT_connect() {
int8_t ret;
if (mqtt.connected()) {
return;
}
Serial.print("Connecting to MQTT... ");
while ((ret = mqtt.connect()) != 0) {
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000);
}
Serial.println("MQTT Connected!");
}

static void smartdelay(unsigned long ms) {
unsigned long start = millis();
do {
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.