Announcement

Collapse
No announcement yet.

Wifi Device Tracking - CSV File Input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Wifi Device Tracking - CSV File Input

    All:

    I've found an app that runs on the Raspberry Pi that will act as a wifi device proximity sensor - it regularly outputs both Access Points and Clients that it sees along with some diagnostic info in a csv file. I'm thinking of using this as the basis as a proximity tracker. The logic of creating the devices from IDs parsed out of the file only if new and updating if existing or flagging 'not there' if not in the parse is intimidating. I'm wondering if anyone knows of a similar script that I could start from?

    I'm including a small extract from the csv file
    Attached Files

    #2
    I don't think there is going to be a good starting script for that because of the fact you have that empty row and then you have two sets of different data. The empty row could be useful though to work out when to move onto the next set of data, what bit of data are you after, the station or bssid or both?

    Creating a table of devices in HS is not that hard work but it is ultimately easier if you have a known device to create the device manually and in turn just update the device which belongs to that specific Wifi device.

    Comment


      #3
      Offerring this code to anyone else that may need to parse a csv file to devices...

      Imports System.IO
      #include wifi_pairs.vb

      Sub Main(Parms As Object)

      Dim FileName As String = "x:your file path"

      If System.IO.File.Exists (FileName) then

      Dim LastUpdate as DateTime
      Dim InpStr As String
      Dim LastLine as String
      Dim strsplit() as String
      Dim Linesplit() as String
      Dim i as integer
      Dim device_name,device_value,device_string as string
      Dim existing_dvref
      Dim dv,dvref
      Dim beacons, power

      LastUpdate=System.IO.File.GetLastWriteTime (FileName)
      dvref=hs.getdevicerefbyname ("Wifi AP Wifi Polling")
      hs.setdevicevaluebyref (dvref, Datediff("n",Now,LastUpdate), True)

      i=0
      InpStr = My.Computer.FileSystem.ReadAllText(FileName)
      strSplit = split(InpStr, vbNewLine)

      Linesplit = split(StrSplit(0),",")

      'skip first header
      Do Until Linesplit(0)="BSSID"
      Linesplit = split(strSplit(i), ",")
      i=i+1
      Loop

      'process Access Points
      Do Until Linesplit(0)=""
      Linesplit = split(strSplit(i), ",")
      i=i+1
      if Linesplit(0)<>"" then
      beacons=cDbl(linesplit(9))
      Power=cDbl(linesplit(8))
      if beacons>1 and Power<>-1 then
      device_name=linesplit(0)
      device_value=linesplit(8)
      device_string=linesplit(13)
      existing_dvref=hs.getdevicerefbyname("Wifi AP "+device_name)
      if existing_dvref=-1 then
      notify_new_device ("Wifi AP "+device_name)
      dvref=hs.NewDeviceref(device_name)
      dv=hs.getdevicebyref(dvref)
      dv.location(hs)="Wifi AP"
      dv.location2(hs)="Neighborhood"
      hs.setdevicevaluebyref(dvref,cDbl(device_value), True)
      hs.setdevicestring(dvref,"New "+Now, True)
      create_pairs(dvref)
      else
      hs.setdevicevaluebyref(existing_dvref,cDbl(device_value), True)
      hs.setdevicelastchange(dvref, Now)
      End If
      End If
      End If
      Loop

      'skip second header
      Do Until Linesplit(0)="Station MAC"
      Linesplit = split(strSplit(i), ",")
      i=i+1
      Loop

      'process clients
      Do Until Linesplit(0)=""
      Linesplit = split(strSplit(i), ",")
      i=i+1
      if Linesplit(0)<>"" then
      device_name=linesplit(0)
      device_value=linesplit(3)
      device_string=linesplit(5)
      existing_dvref=hs.getdevicerefbyname("Wifi Client "+device_name)
      if existing_dvref=-1 then
      notify_new_device ("Wifi Client "+device_name)
      dvref=hs.NewDeviceref(device_name)
      dv=hs.getdevicebyref(dvref)
      dv.location(hs)="Wifi Client"
      dv.location2(hs)="Neighborhood"
      hs.setdevicevaluebyref(dvref,cDbl(device_value), True)
      hs.setdevicestring(dvref,"New "+Now, True)
      create_pairs(dvref)
      else
      hs.setdevicevaluebyref(existing_dvref,cDbl(device_value), True)
      hs.setdevicelastchange(dvref, Now)
      End If
      End If
      Loop

      else
      hs.writelog ("file not found", FileName)
      End If
      End Sub

      Sub notify_new_device (name)

      hs.writelog ("New WIFI", name)
      device",name,"")

      End Sub

      sub create_pairs (Byval Parms as Object)
      dim ref
      dim GPair as VGPair
      dim SPair as VSPair
      dim parameters() as string
      dim location as string
      dim name as string

      if parms is nothing then
      hs.writelog ("wifi_pairs.vb","no parms specified")
      else
      ref=parms
      end if

      if ref<>0 then
      '0
      GPair = New VGPair
      SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Status)
      GPair.PairType = VSVGPairType.Range
      SPair.PairType = VSVGPairType.Range
      GPair.RangeStart = -100
      SPair.RangeStart = -100
      GPair.RangeEnd = -85
      SPair.RangeEnd = -85
      GPair.Graphic = "/images/wifi/antenna_0.png"
      SPair.RangeStatusPrefix = "Very Far "
      Spair.RangeStatusSuffix = " dBm"
      Spair.RangeStatusDecimals = 0
      Spair.RangeStatusDivisor = 1
      Spair.IncludeValues = True
      hs.DeviceVGP_AddPair(ref, GPair)
      hs.DeviceVSP_AddPair(ref, SPair)
      '25
      GPair = New VGPair
      SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Status)
      GPair.PairType = VSVGPairType.Range
      SPair.PairType = VSVGPairType.Range
      GPair.RangeStart = -84
      SPair.RangeStart = -84
      GPair.RangeEnd = -60
      SPair.RangeEnd = -60
      GPair.Graphic = "/images/wifi/antenna_25.png"
      SPair.RangeStatusPrefix = "Far "
      Spair.RangeStatusSuffix = " dBm"
      Spair.RangeStatusDecimals = 0
      Spair.RangeStatusDivisor = 1
      Spair.IncludeValues = True
      hs.DeviceVGP_AddPair(ref, GPair)
      hs.DeviceVSP_AddPair(ref, SPair)
      hs.writelog ("test", VSVGPairType.Range)
      '50
      GPair = New VGPair
      SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Status)
      GPair.PairType = VSVGPairType.Range
      SPair.PairType = VSVGPairType.Range
      GPair.RangeStart = -59
      SPair.RangeStart = -59
      GPair.RangeEnd = -40
      SPair.RangeEnd = -40
      GPair.Graphic = "/images/wifi/antenna_50.png"
      SPair.RangeStatusPrefix = "Close "
      Spair.RangeStatusSuffix = " dBm"
      Spair.RangeStatusDecimals = 0
      Spair.RangeStatusDivisor = 1
      Spair.IncludeValues = True
      hs.DeviceVGP_AddPair(ref, GPair)
      hs.DeviceVSP_AddPair(ref, SPair)
      hs.writelog ("test", VSVGPairType.Range)
      '100
      GPair = New VGPair
      SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Status)
      GPair.PairType = VSVGPairType.Range
      SPair.PairType = VSVGPairType.Range
      GPair.RangeStart = -39
      SPair.RangeStart = -39
      GPair.RangeEnd = 0
      SPair.RangeEnd = 0
      GPair.Graphic = "/images/wifi/antenna_100.png"
      SPair.RangeStatusPrefix = "Very Close "
      Spair.RangeStatusSuffix = " dBm"
      Spair.RangeStatusDecimals = 0
      Spair.RangeStatusDivisor = 1
      Spair.IncludeValues = True
      hs.DeviceVGP_AddPair(ref, GPair)
      hs.DeviceVSP_AddPair(ref, SPair)
      hs.writelog ("test", VSVGPairType.Range)

      end if

      end sub

      Comment

      Working...
      X