updts to scanstuff / trying to resolve git issue
This commit is contained in:
commit
a3839ec603
21
main.go
21
main.go
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"protomolecule/src/dust"
|
||||
"protomolecule/src/eros"
|
||||
@ -11,7 +10,6 @@ import (
|
||||
|
||||
projVars "protomolecule/src/vars"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"tinygo.org/x/bluetooth"
|
||||
@ -35,7 +33,7 @@ func init() {
|
||||
// define log file itself using the current date and time
|
||||
Now := time.Now()
|
||||
date := Now.Format(time.RFC3339)
|
||||
logFileName := "protomolecule-" + date
|
||||
logFileName := date + ".log"
|
||||
lf, err := os.OpenFile(logDir+logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
@ -55,38 +53,37 @@ func main() {
|
||||
|
||||
scanStuff.Scanners()
|
||||
|
||||
color.Red("Searching for: ")
|
||||
for _, word := range values {
|
||||
fmt.Print(word)
|
||||
}
|
||||
log.Info().Strs("target", values).Msg("Searching")
|
||||
|
||||
/*
|
||||
err := adapter.Enable()
|
||||
if err != nil {
|
||||
println("BLE stack unstable, could not enable", err.Error())
|
||||
log.Fatal().Err(err).Msg("BLE stack unstable, could not enable")
|
||||
return
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//var foundDevice bluetooth.ScanResult
|
||||
|
||||
//turn the stuff on
|
||||
dust.Must("BLE stack", projVars.ScanAdapter.Enable())
|
||||
|
||||
println("Scanning")
|
||||
log.Info().Msg("Scanning")
|
||||
err := projVars.ScanAdapter.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) {
|
||||
|
||||
if result.Address.String() == *projVars.Target {
|
||||
|
||||
color.Cyan("found device:", result.Address.String(), result.RSSI, result.LocalName())
|
||||
log.Info().Str("address", result.Address.String()).
|
||||
Int16("RSSI", result.RSSI).Str("LocalName",result.LocalName())
|
||||
}
|
||||
/*
|
||||
if err != nil {
|
||||
println("could not enable the stack", err.Error())
|
||||
log.Error().Err(err).Msg("could not enable the stack", err.Error())
|
||||
return
|
||||
}
|
||||
*/
|
||||
})
|
||||
|
||||
dust.Must("scanns n stuff", err)
|
||||
|
||||
/*
|
||||
|
@ -3,6 +3,7 @@ package scanStuff
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"protomolecule/src/dust"
|
||||
"protomolecule/src/eros"
|
||||
projVars "protomolecule/src/vars"
|
||||
@ -13,10 +14,10 @@ import (
|
||||
func Scanners() {
|
||||
|
||||
//create list of devices in the AO
|
||||
println("Creating Device Map")
|
||||
log.Debug().Msg("Creating Device Map")
|
||||
dust.FirstList()
|
||||
|
||||
println("Enabling Adapter")
|
||||
log.Info().Msg("Enabling Adapter")
|
||||
// Enable BLE interface.
|
||||
dust.Must("enable BLE stack", projVars.ScanAdapter.Enable())
|
||||
|
||||
@ -25,16 +26,21 @@ func Scanners() {
|
||||
|
||||
//TODO: only scan a device once, skip if its in the map
|
||||
// Start scanning.
|
||||
println("scanning...")
|
||||
// redundant(?): log.Info().Msg("scanning...")
|
||||
|
||||
//results := new(bluetooth.ScanResult)
|
||||
|
||||
projVars.ScanAdapter.Scan(func(scanAdapter *bluetooth.Adapter, device bluetooth.ScanResult) {
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 29dc71980394d77fbde57905befab1a486a49e27
|
||||
if device.LocalName() != projVars.ScanList[device.Address.String()] {
|
||||
color.Cyan("found device:")
|
||||
println(device.Address.String(), device.RSSI, device.LocalName())
|
||||
println(device.AdvertisementPayload)
|
||||
log.Info().Str("address", device.Address.String()).
|
||||
Str("LocalName", device.LocalName()).
|
||||
Int16("RSSI", device.RSSI).Str("AdvertisementPayload", string(device.AdvertisementPayload.Bytes())).
|
||||
Msg("new_device_found")
|
||||
|
||||
//for _, uuid := range device.AdvertisementFields.ServiceUUIDs {
|
||||
|
||||
//places captured devices into the eros DB
|
||||
|
Loading…
Reference in New Issue
Block a user