services

Python

Scripting is nice

Scripting in Python is fast thanks to its human-readable syntax. There are tons of resources and libraries over the Internet. A good choice for prototyping. And it’s free!

Use cases

Flask is more customazible than the Django framework, although it requires some file editing for Back-end services. Take a look: Python Flask - Javascript Lightweight Gallery - agalvez.es

Python HTTP server

We can call Python modules from the terminal without the need of an IDE. Let’s run a simple instance for a server-client file exchange:

Open a terminal inside the directory of choice. Then simply use the command:

$ python -m http.server

Notice the -m flag stands for ‘module’. In certain distros you may invoke this server with python3 instead of python. This command should be available also on Windows.

Check available IPs on your computer:

  • Linux:
$ ip -c a
  • Windows:
> ipconfig

Then the file may be retrieved with a GET request:

$ wget http://0.0.0.0:8000/file

This workflow may be convinient for single file download requests. For bigger transfer volumes you may consider other utils such as rsync.

Python MQTT client

Check this post: Skills - iOT

[Code] Client.py

#!/usr/bin/python3

import paho.mqtt.client as mqtt 
from random import randrange, uniform
import time

#mqttBroker ="mqtt.eclipseprojects.io" 

client = mqtt.Client("LOCAL-MSSG")
#client.connect(mqttBroker) 
client.connect("127.0.0.1",1883,60) 

while True:
    randNumber = uniform(20.0, 21.0)
    client.publish("This is a test message for agalvez.es", randNumber)
    print("Just published " + str(randNumber) + " to topic LOCAL-MSSG")
    time.sleep(1)