Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/geolocation #5

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore

# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

# Android Profiling
*.hprof

# Cordova plugins for Capacitor
capacitor-cordova-android-plugins

# Copied web assets
app/src/main/assets/public

# Generated Config files
app/src/main/assets/capacitor.config.json
app/src/main/assets/capacitor.plugins.json
app/src/main/res/xml/config.xml
20 changes: 20 additions & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-community-background-geolocation')
implementation project(':capacitor-community-bluetooth-le')

}


if (hasProperty('postBuildExtras')) {
postBuildExtras()
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
mavenCentral()
Expand Down
9 changes: 9 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-community-background-geolocation'
project(':capacitor-community-background-geolocation').projectDir = new File('../node_modules/@capacitor-community/background-geolocation/android')

include ':capacitor-community-bluetooth-le'
project(':capacitor-community-bluetooth-le').projectDir = new File('../node_modules/@capacitor-community/bluetooth-le/android')
6 changes: 3 additions & 3 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'senseBox:Bike X SIMPORT',
webDir: 'out',
server: {
url: 'http://192.168.0.220:3000',
},
// server: {
// url: 'http://192.168.0.220:3000',
// },
}

export default config
8 changes: 8 additions & 0 deletions ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@
<array>
<string>bluetooth-central</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need to track your location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need to track your location while your device is locked.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install! 'cocoapods', :disable_input_output_paths => true
def capacitor_pods
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCommunityBackgroundGeolocation', :path => '../../node_modules/@capacitor-community/background-geolocation'
pod 'CapacitorCommunityBluetoothLe', :path => '../../node_modules/@capacitor-community/bluetooth-le'
end

Expand Down
8 changes: 7 additions & 1 deletion ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
PODS:
- Capacitor (5.3.0):
- CapacitorCordova
- CapacitorCommunityBackgroundGeolocation (0.0.1):
- Capacitor
- CapacitorCommunityBluetoothLe (3.0.1):
- Capacitor
- CapacitorCordova (5.3.0)

DEPENDENCIES:
- "Capacitor (from `../../node_modules/@capacitor/ios`)"
- "CapacitorCommunityBackgroundGeolocation (from `../../node_modules/@capacitor-community/background-geolocation`)"
- "CapacitorCommunityBluetoothLe (from `../../node_modules/@capacitor-community/bluetooth-le`)"
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"

EXTERNAL SOURCES:
Capacitor:
:path: "../../node_modules/@capacitor/ios"
CapacitorCommunityBackgroundGeolocation:
:path: "../../node_modules/@capacitor-community/background-geolocation"
CapacitorCommunityBluetoothLe:
:path: "../../node_modules/@capacitor-community/bluetooth-le"
CapacitorCordova:
:path: "../../node_modules/@capacitor/ios"

SPEC CHECKSUMS:
Capacitor: 1ac9165943bc4f2137642d218c5ba05df811de69
CapacitorCommunityBackgroundGeolocation: 6f26f4290377dbd1d6dec21e62cb66f008f61ec7
CapacitorCommunityBluetoothLe: 308770c1ee9499c216776159326bc2b9a49076b4
CapacitorCordova: b9374d68e63ce29e96ab5db994cf14fbefd722c9

PODFILE CHECKSUM: 209b88b5339b30dc7f4dfccad65ac57cc69b251e
PODFILE CHECKSUM: 6e41747aee00f59e1e4a8249f9aa31ede26dcdf5

COCOAPODS: 1.11.3
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"static": "next build && next export"
},
"dependencies": {
"@capacitor-community/background-geolocation": "^1.2.14",
"@capacitor-community/bluetooth-le": "^3.0.1",
"@capacitor/android": "^5.3.0",
"@capacitor/core": "^5.3.0",
Expand Down
17 changes: 6 additions & 11 deletions src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Navbar } from '@/components/ui/Navbar'
import { TopBar } from '@/components/ui/TopBar'
import { Button } from '@/components/ui/button'
import {
AcademicCapIcon,
BellIcon,
ExclamationTriangleIcon,
} from '@heroicons/react/24/outline'
import Image from 'next/image'
import Logo from '../../public/bike.png'
import Geolocation from '@/components/Geolocation'

export default function Home() {
return <div className="flex h-full w-full flex-col">des</div>
return (
<div className="flex h-full w-full flex-col">
<Geolocation />
</div>
)
}
124 changes: 67 additions & 57 deletions src/app/device/page.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,77 @@
"use client";
import MapComponent from "@/components/Map/Map";
import {
BeakerIcon,
ChartBarIcon,
CloudIcon,
PauseIcon,
PlayIcon,
RssIcon,
SignalIcon,
SunIcon,
TruckIcon,
} from "@heroicons/react/24/outline";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { cx } from "class-variance-authority";
import { Settings2Icon, SettingsIcon } from "lucide-react";
import { useState } from "react";
import { DialogTrigger } from "@radix-ui/react-dialog";
import SettingsModal from "@/components/Map/Settings";
import RecordButton from "@/components/Map/RecordButton";
import MeasurementsOverview from "@/components/Map/MeasurementsOverview";
import ControlBar from "@/components/Map/ControlBar";
'use client'

import MapComponent from '@/components/Map/Map'
import { useEffect, useState } from 'react'
import MeasurementsOverview from '@/components/Map/MeasurementsOverview'
import ControlBar from '@/components/Map/ControlBar'
import useSenseBox from '@/lib/useSenseBox'
import { Source, Layer } from 'react-map-gl/maplibre'

export default function Home() {
const [recording, setRecording] = useState(false);
const [recording, setRecording] = useState(false)

const [data, setData] = useState({
temperature: 0,
humidity: 0,
pm1: 0,
pm25: 0,
pm4: 0,
pm10: 0,
accelerationX: 0,
accelerationY: 0,
accelerationZ: 0,
speed: 0,
});
const toggleRecording = () => {
setRecording(!recording);
};
const { values, connect, isConnected, disconnect } = useSenseBox()

useEffect(() => {
if (recording && !isConnected) {
connect()
return
}
if (!recording && isConnected) {
disconnect()
return
}
})

return (
<div className="h-full w-full">
<MapComponent />
<div className="flex flex-col">
<div className="absolute left-5 top-20">
<MeasurementsOverview data={data} />
</div>
<div className="absolute top-20 right-5 ">
<RecordButton recording={recording} />
</div>
<div className="absolute bottom-20 right-5 ">
<ControlBar recording={recording} toggleRecording={toggleRecording} />
</div>
</div>
<div className="relative h-full w-full">
<MapComponent>
<Source
id="location"
type="geojson"
data={{
type: 'Point',
coordinates: [
values.at(-1)?.gps_lat || 0,
values.at(-1)?.gps_lng || 0,
],
}}
>
<Layer
id="point"
type="circle"
paint={{
'circle-radius': 10,
'circle-color': '#007cbf',
}}
/>
</Source>
<Source
id="location-history"
type="geojson"
data={{
features: values.map(v => ({
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [v.gps_lat || 0, v.gps_lng || 0],
},
})),
type: 'FeatureCollection',
}}
>
<Layer id="point" type="line" />
</Source>
</MapComponent>
<div className="pointer-events-none absolute inset-0 left-0 top-0 flex h-full w-full flex-col items-center justify-between gap-2 p-4">
<MeasurementsOverview data={values.at(-1)} isConnected={isConnected} />

<ControlBar
recording={recording}
toggleRecording={() => setRecording(!recording)}
/>
</div>
</div>
)
}
15 changes: 7 additions & 8 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { TopBar } from "@/components/ui/TopBar";
import "../styles/globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { Navbar } from "@/components/ui/Navbar";
import { cn } from "@/lib/utils";
import { Toaster } from "@/components/ui/toaster";

import { TopBar } from '@/components/ui/TopBar'
import '../styles/globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { Navbar } from '@/components/ui/Navbar'
import { cn } from '@/lib/utils'
import { Toaster } from '@/components/ui/toaster'

const inter = Inter({ subsets: ['latin'] })

Expand Down
Loading