README.md 1.6 KB
Newer Older
Michele Fiori's avatar
Michele Fiori committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
# Setup REST and MQTT



* You can import the project directly from a *Version Control System*, by providing the following URL: 
https://ewserver.di.unimi.it/gitlab/michelefiori/Lab4-Examples

<img src = './assets/img_1.png'>


* Otherwise, take care to import the project as a Gradle Project
* If required, trust the project and accept the Gradle auto-import
* Wait until the Gradle indexing process ends (it may take a few seconds)

## REST

* Run StartServer.java located in: *REST\_MQTT_example/src/main/java/REST/*
    * Don't worry about the red *INFO* console prints
* Use a REST Client application (i.e., Advanced REST Client) to test if the server works correctly
* For example you can run the following request:

<img src = './assets/img_2.jpeg'>


## MQTT
* Mac OS:
  * Install homebrew from (https://brew.sh/index_it)
  * From the terminal:  
    `brew install mosquitto`  
    `brew services start mosquitto`  
    … running …  
    `brew services stop mosquitto`
* Windows:
  * Download and install the mosquitto broker from https://mosquitto.org/download/
  * Launch the mosquitto.exe file from C:\Program Files\Mosquitto
* Linux (http://www.steves-internet-guide.com/install-mosquitto-linux/):
  * From the terminal:  
    `sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa`  
    `sudo apt-get update`  
    `sudo apt-get install mosquitto`  
    `sudo apt-get install mosquitto-clients`  
    `sudo apt clean`  
    `sudo service mosquitto start`  
    ... running …  
    `sudo service mosquitto stop`  


You can try to run the class SubExample and then the class PubExample to test that everything is working.