In [2]:
import numpy as np
import pandas as pd

In [3]:
def rssi_to_distance(rssi):

    ### Declare local variable TxPower
    # This is value of rssi @ 1m
    TxPower = -65
    ratio = rssi * 1.0 / TxPower
    
    # If rssi was 0
    if (rssi == 0):
      return -1
    
    if (ratio < 1.0):
        return ratio**10
    else:
      dist = (0.89976) * (ratio ** 7.7095) + 0.111
    return dist

In [4]:
RSSI = range(-100,-40)

In [9]:
d = {}
for r in RSSI:
    d[r] = rssi_to_distance(r)

In [10]:
d


Out[10]:
{-100: 25.02658904726947,
 -99: 23.168949933183047,
 -98: 21.433031943273445,
 -97: 19.811980648664818,
 -96: 18.299263200665816,
 -95: 16.888656326717445,
 -94: 15.574234656988484,
 -93: 14.35035937581255,
 -92: 13.211667192204192,
 -91: 12.153059623733682,
 -90: 11.169692588083686,
 -89: 10.256966296653632,
 -88: 9.410515444621531,
 -87: 8.626199691915767,
 -86: 7.900094429593407,
 -85: 7.228481826164924,
 -84: 6.607842148449466,
 -83: 6.034845351588396,
 -82: 5.50634293288929,
 -81: 5.019360044216557,
 -80: 4.571087857689661,
 -79: 4.158876179494165,
 -78: 3.7802263066558126,
 -77: 3.432784121672608,
 -76: 3.1143334199451074,
 -75: 2.82278946499021,
 -74: 2.5561927664692594,
 -73: 2.3127030761067466,
 -72: 2.0905935966217934,
 -71: 1.888245398840386,
 -70: 1.7041420422025293,
 -69: 1.536864393924718,
 -68: 1.3850856421246824,
 -67: 1.247566498261941,
 -66: 1.1231505842946197,
 -65: 1.01076,
 -64: 0.8563793241047093,
 -63: 0.7315970205097451,
 -62: 0.6234237290152215,
 -61: 0.5298644513991109,
 -60: 0.44913710714186356,
 -59: 0.37965274997577403,
 -58: 0.3199973407138298,
 -57: 0.2689149768284991,
 -56: 0.2252924841036363,
 -55: 0.18814528037496547,
 -54: 0.15660442590925155,
 -53: 0.12990477935188902,
 -52: 0.10737418240000006,
 -51: 0.08842360043586965,
 -50: 0.07253815028640576,
 -49: 0.05926895006094422,
 -48: 0.048225729664858795,
 -47: 0.03907014409274539,
 -46: 0.03150973497515332,
 -45: 0.02529248908960331,
 -44: 0.020201945652680697,
 -43: 0.016052807187998838,
 -42: 0.012687011617503758,
 -41: 0.009970225953618508}

In [16]:
import matplotlib.pylab as plt

In [21]:
lists = sorted(d.items())
x, y = zip(*lists)
plt.plot(y, x)
plt.xlabel('Distance [m]')
plt.ylabel('RSSI values')
plt.show()



In [56]:
import numpy as np
import random

random_rssi = []
random_sourceId = []
random_time = []
random_source_number = []

for x in range(600):
    random_rssi.append(random.randint(-100,-40))
    random_sourceId.append(random.choice(list_sourceIds))
    random_time.append(random.randint(0,200))
    random_source_number.append(random.randint(0,6))

In [21]:
list_sourceIds = ['8JRGb', '9McaT', 'H3vx9', 'HNenF', 'QQhDc','ZN6Xd', 'rNt0R']

In [74]:
import pandas as pd

labels = ['Time', 'RSSI', 'sourceId']
dfA = pd.DataFrame(random_time, columns=['Time'])
dfB = pd.DataFrame(random_sourceId, columns=['sourceId'])
dfC = pd.DataFrame(random_rssi, columns=['rssi'])
dfD = pd.concat([dfA, dfB], join='outer', axis=1)

df = pd.concat([dfD, dfC], join='outer', axis=1)
df.head()

import matplotlib.pyplot as plt

area = 12
plt.xlabel('Time [s]')
plt.ylabel('Source Id')
plt.yticks(df.index, list_sourceIds)
plt.scatter(df['Time'], random_source_number, s=area, c=df['rssi'], alpha=0.8)
plt.colorbar()

plt.show()



In [ ]: