Software apps and online services
This tutorial will cover how to distantly monitor PC activity, from anywhere, without requiring it to be connected to the Internet. This kind of system could be used to remotely detect, track and report special events triggered on a computer.Hardware
This board has a USB adapter which allows serial communication. We will use a simple Python script to communicate with AT commands.
For this tutorial, the goal is to check the idle time and send a message over Sigfox accordingly. This can be useful to detect if someone is using your PC or calculate the time spent on it for example. You may also play with the
module if you wish to detect other kind of information (softwares being used, keylogging 😈, ...).
- Python 2.7 or over
- A Windows operating system
- Python modules:
pip install pyserial pip install pypiwin32 pip install binascii
- Set the correct COM port in
- Activate your device on the Sigfox Backend (follow this link for the M2COMM provider). You will need the device ID and PAC. Use the functions
main.pyto get them.
The boards LED should turn red when a message is being sent over Sigfox. Make sure the messages are well received on the Sigfox Backend. Log in, go to the DEVICE section and click left on your device Id. You can than go the MESSAGES section to see the payloads.
The Python script can be launched as a background Windows task when a user session is opened for example. You can
this file on the Windows Task Scheduler (you can also find the file in the task folder).
is used to launch a Python script as a background process on Windows. Make sure you have it installed on your machine (mine is located here C:\Python27\pythonw.exe).
Below are the defined conditions to report activity:
# Check if there is activity (less than 10 minutes) if(idleTime <= 60 * 10): # idleTime over 8 minutes if(idleTime >= 60 * 8): sigfox.sendPayload("25") # idleTime over 4 minutes elif(idleTime >= 60 * 4): sigfox.sendPayload("50") # idleTime less than 4 minutes else: sigfox.sendPayload("100") # idleTime over 10 minutes else: sigfox.sendPayload("0")
This snippet is looped every 10 minutes.
In order to send a message over Sigfox, we are establishing a serial communication with the board and sending the corresponding AT command (check it out in the `Sigfox()` class):
def sendPayload(self, frame): bytesFrame = str.encode(frame) hexFrame = str(binascii.hexlify(bytesFrame)).encode('ASCII') cmd = "\rAT$SF=" + hexFrame + "\r\n" self.ser.write(cmd.encode()) print("--------------------------------") print(self.ser.readline().rstrip('\r\n')) print(self.ser.readline().rstrip('\r\n')) print(self.ser.readline().rstrip('\r\n'))
The payload must be converted to hexadecimal and cannot be larger than 12 bytes.[Optional] Going further - web application
If you wish to retrieve and display the Sigfox messages on a personal web application, you are free to use the one I developed (in folder
). It plots a graph in real time with the data sent from the Python script (values between 0 and 100) and saves the payloads in a database.
In order to make it work, you will also have to set a CALLBACK on the Sigfox Backend pointing to your application URL and posting the devices data. You can have a look at this tutorial to get some help on how to do that.
This web application is built with Node.js and uses:
- MongoDB to store incoming messages
- EJS pages
- Websockets for live data visualization (Socket.io)
- and many more npm packages
git clone https://github.com/AntoinedeChassey/sigfox_activity_monitoring cd sigfox_activity_monitoring/webapp # Update the DB_URI variable in .env so it matches your own MongoDB configuration nano .env sudo npm install sudo node server.js
Have fun hacking this to build cool things! Also, feel free to post your Python scripts if you add some nice features. 😎
Antoine de Chassey