Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- #include <TinyGPS++.h>
- #include <WiFi.h>
- // Define pin numbers
- #define DHTPIN 4
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- WiFiClient client;
- TinyGPSPlus gps;
- const char* ssid = "your_network_name";
- const char* password = "your_network_password";
- const char* server = "your_cloud_server.com"; // e.g., ThingSpeak or Firebase
- void setup() {
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi");
- dht.begin();
- }
- void loop() {
- // GPS data reading
- while (Serial.available() > 0) {
- gps.encode(Serial.read());
- }
- // Get data from GPS
- if (gps.location.isUpdated()) {
- float latitude = gps.location.lat();
- float longitude = gps.location.lng();
- Serial.print("Latitude= "); Serial.print(latitude, 6);
- Serial.print(" Longitude= "); Serial.println(longitude, 6);
- }
- // Get pet activity from accelerometer (simplified)
- int x = analogRead(A0); // Just a placeholder, use accelerometer API here
- int y = analogRead(A1);
- int z = analogRead(A2);
- // Get temperature and humidity data
- float temp = dht.readTemperature();
- float humidity = dht.readHumidity();
- // Send data to the cloud (simplified)
- if (client.connect(server, 80)) {
- client.print("GET /update?latitude=");
- client.print(gps.location.lat());
- client.print("&longitude=");
- client.print(gps.location.lng());
- client.print("&temperature=");
- client.print(temp);
- client.print("&humidity=");
- client.print(humidity);
- client.print("&activity_x=");
- client.print(x);
- client.print("&activity_y=");
- client.print(y);
- client.print("&activity_z=");
- client.print(z);
- client.println(" HTTP/1.1");
- }
- delay(1000); // Adjust delay based on the sampling rate you want
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement