Skip to content

Instantly share code, notes, and snippets.

@andysign
Last active February 27, 2023 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andysign/a8ad8df9f0f0492f0cd6af38f05c4c82 to your computer and use it in GitHub Desktop.
Save andysign/a8ad8df9f0f0492f0cd6af38f05c4c82 to your computer and use it in GitHub Desktop.
README-hardware-integration.md

Table of Contents generated with DocToc

WIZ Middleware Server

This is designed to explain how to use the Wiz Dev Server.

The architecture diagram of this system is presented below. Section 2). represents this group of API endpoints described in this document here. If you want to learn more about the others, see below.

┌─────────────────┐          ┌────────────────────────────────────┐          ┌─────────────────────────────┐
│                 │          │                                    │          │                             │
│ IRIS            │ ───────► │ PrivateMiddleware                  │ ───────► │ RDIUP                       │
│                 │          │                                    │          │                             │
│ DigitalPlatform │ ◄─────── │ WIZ + DC                           │ ◄─────── │ Python                      │
│                 │          │                                    │          │                             │
└─────────────────┘          │ ┌────────────────────────────────┐ │ OR       └─────────────────────────────┘
                             │ │                                │ │ Fallback
 1).                         │ │ Software Middleware w fallback │ │          ┌─────────────────────────────┐
                             │ │                                │ │ ───────► │                             │
                             │ │ PORT: 3000                     │ │          │ MongoDb                     │
                             │ │                                │ │ ◄─────── │                             │
                             │ └────────────────────────────────┘ │          └─────────────────────────────┘
                             │                                    │
────────────────────────     │ ────────────────────────────────── │ ────────────────────────────────────────
                             │                                    │
 2).                         │                                    │
                             │                                    │
┌─────────────────┐          │ ┌────────────────────────────────┐ │          ┌─────────────────────────────┐
│                 │          │ │                                │ │          │                             │
│ IRIS            │ ───────► │ │ Hardware Middleware Prime OLD  │ │          │ Static Backend              │
│                 │          │ │                                │ │ ◄─────── │                             │
│ DigitalPlatform │ ◄─────── │ │ PORT: 3001                     │ │          │ Read-Only Data (expressJs)  │
│                 │          │ │                                │ │          │                             │
└─────────────────┘          │ └────────────────────────────────┘ │          └─────────────────────────────┘
                             │                                    │
 3).                         │                                    │
                             │                                    │
┌─────────────────┐          │ ┌────────────────────────────────┐ │
│                 │          │ │                                │ │          ┌─────────────────────────────┐
│ CODY            │ ───────► │ │ Hardware Middleware (Virtual)  │ │ ───────► │                             │
│                 │          │ │                                │ │          │ MongoDb                     │
│ HardwareBackEnd │ ◄─────── │ │ PORT: 3003                     │ │ ◄─────── │                             │
│                 │          │ │                                │ │          └─────────────────────────────┘
└─────────────────┘          │ └────────────────────────────────┘ │
                             │                                    │
                             └────────────────────────────────────┘

To read the full documentation for all the other sections see below:

For Section 1)., use the link: https://gist.github.com/andysign/d5f546c38eb559510ed1b0c4f8b7992e

For Section 3)., use the link: https://gist.github.com/andysign/6d38c10bdfca83a2500ac495ad3c79f7


Project Structure And Starting Instructions

This section describes the folder structure and how to start the project.


Project Structure And Starting Instructions: Folder Structure

The project can be found in:

/c/work/diy4u-hardware

Note: You can use Power Shell, Command Prompt or Git Bash to access it.


Project Structure And Starting Instructions: Starting The Project

Check Task Manager and make sure there is no node.exe process running. After that navigate to /c/work/diy4u-hardware in bash and type:

npm start

Remote Connection

Remote connections are also available for uploading or downloading code.


Remote Connection: FTP Connection

  • Port: 21
  • Username: admin
  • Pwd: crC5mtU9AdQ3JP!

By default all files uploaded trough the ftp will go in:

C:\inetpub\vhosts\trusting-sinoussi.207-244-228-246.plesk.page\httpdocs\diy4u-hardware\

Every static html file uploaded here will be accessible using the link below:

http://207.244.228.246/plesk-site-preview/trusting-sinoussi.207-244-228-246.plesk.page/


Remote Connection: SSH Connection

No SSH connection!


Remote Desktop

The main server can be controlled remotely using the following credentials.


Remote Desktop: Main Remote Desktop Connection

  • IP: 207.244.228.246
  • Username Administrator
  • Password: crC5mtU9AdQ3JP

Remote Desktop: Remote Desktop Connection One

  • Username: diy4you1
  • New Password: diy4u!

Remote Desktop: Remote Desktop Connection Two

  • Username: diy4you2
  • New Password: diy4u!

Remote Desktop: Remote Desktop Connection Three

  • Username: diy4you3
  • New Password: diy4u!

API Endpoints

All current endpoints should contain the version ( v1 ) in the path.


API Endpoints: Root

  • Endpoint: / OR /api/v1/
curl -X GET 'http://207.244.228.246:3001/'; echo
  • Expected Result:
{ "result": "Demo Hardware Middleware API." }

API Endpoints: GET Api Status

  • Endpoint: /api/v1/status
curl -X GET 'http://207.244.228.246:3001/api/v1/status'; echo
  • Expected Result:
{"result":"Middleware is up and running."}

API Endpoints: GET FabLab status base on FabLab Id

  • Endpoint: /api/v1/fablab-status/:id
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab-status/1'; echo
  • Expected Result:
{ "id": "1", "status": "READY / NOT_READY" }

API Endpoints: GET Order status base on Order Id

  • Endpoint: /api/v1/order-status/:id
curl -X GET 'http://207.244.228.246:3001/api/v1/order-status/1'; echo
  • Expected Result:
{"id":"1","status":"WAITING / FINISHED"}

API Endpoints: GET Slots base on FabLab Id DEPRECIATED

  • Endpoint DEPRECIATED: /api/v1/fablab/:id/slots
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab/101/slots'; echo
  • Expected Result:
{
"id": "101",
"slots": [
  { "id": 1, "serialNo": 1, "modelWidth": 1 },
  { "id": 2, "serialNo": 2, "modelWidth": 1 }
]
}

API Endpoints: GET FabLab conf based on SerialNumber

  • Endpoint: /api/v1/fablab-conf-by-serial-no/:sn
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab-conf-by-serial-no/XY123'; echo
  • Expected Result:
{ "serialNo": "XY123",
  "modules": [
    {
      "serialNo": "ABCD1234",
      "position": 1,
      "moduleWidth": 1,
      "subModules": [ { "serialNo": "11HXU2QT", "subModuleType": 1001 } ]
    }
  ]
}

API Endpoints: GET ALL ids of ALL orders

  • Endpoint: /api/v1/all-order-ids
curl -X GET 'http://207.244.228.246:3001/api/v1/all-order-ids'; echo
  • Expected Result:
[ { "orderId": 101, "forFablabSn": "JSDAHFJSAHFKADF" },
  { "orderId": 102, "forFablabSn": "SAHFKJSDAHFJADF" },
  { "orderId": 103, "forFablabSn": "HFKJSAADFDAHFJS" } ]

API Endpoints: GET the IDs of ALL orders for a FabLab based on FabLab SerialNumbers

  • Endpoint: /api/v1/fablab-order-ids-by-serial-no/:sn
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab-order-ids-by-serial-no/ABC123'; echo
  • Expected Results:
[ { "orderId":101, "forFablabSn": "ABC123" } ]

API Endpoints: GET oldest Order, aka Next Order, based on FabLab SerialNumber

  • Endpoint: /api/v1/fablab-next-order-id-by-serial-no/:sn
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab-next-order-id-by-serial-no/XYZ123'; echo
  • Order Details:
{ "orderId": 101, "forFablabSn": "XYZ123" }

---

### API Endpoints: GET Order by OrderId

* Endpoint: `/api/v1/fablab-order-by-id/:id`
```sh
curl -X GET 'http://207.244.228.246:3001/api/v1/fablab-order-by-id/101'; echo
  • Order Details:
{ "order": {
    "date": "2022-05-03T08:48:53.577Z",
    "status": "PENDING",
    "forFablabSn": "XYZ123",
    "operations": [
      { "index": 0, "moduleSerialNo": "MNP456",
        "submoduleSerialNo": "ABC777", "functionId": 13,
        "parameters": [
          { "name": "speed", "value": 11.2, "type": "float" },
          { "name": "time", "value": 1000, "type": "float" } ],
        "HMIInfo": "Dispensing an int num of Units of salt"
      }
    ]
  }
}

API Endpoints: POST new or updated Order with updated Status

  • Endpoint: /api/v1/fablab-order-by-id
  • Note: If body is empty ( as body is in '{}' ) will call will use a hard-coded body
curl -X POST \
-H 'Content-Type: application/json' \
-d '{
    "order": {
        "id": 101, "date": "2022-04-06T11:41:08.361Z",
        "status": "IN_PROGRESS", "forFablabSn": "XYZ123",
        "operations": [ {
            "index": 0, "moduleSerialNo": "DFE123",
            "submoduleSerialNo": "ABC987", "functionId": 11,
            "parameters": [ { "name": "revolutions", "value": 2, "type": "integer" } ],
            "HMIInfo": "Dispensing an int num of Units of salt"
        } ]
    }
}' 'http://207.244.228.246:3001/api/v1/fablab-order-by-id' ; echo
  • Expected Result: Same as the data object above

API Postman Collection

{
	"info": {
		"_postman_id": "3e16398a-ae2f-4dd7-9312-f04f3349fae0",
		"name": "DIY4U",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Root",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						""
					]
				}
			},
			"response": []
		},
		{
			"name": "Api Status",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/status",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"status"
					]
				}
			},
			"response": []
		},
		{
			"name": "FabLab status base on FabLab Id",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/fablab-status/1",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"fablab-status",
						"1"
					]
				}
			},
			"response": []
		},
		{
			"name": "Slots base on FabLab Id",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/fablab/101/slots",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"fablab",
						"101",
						"slots"
					]
				}
			},
			"response": []
		},
		{
			"name": "Order status base on Order Id",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/order-status/1",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"order-status",
						"1"
					]
				}
			},
			"response": []
		},
		{
			"name": "FabLab conf based on serial number",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/fablab-conf-by-serial-no/XY123",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"fablab-conf-by-serial-no",
						"XY123"
					]
				}
			},
			"response": []
		},
		{
			"name": "FabLab order IDs based on FabLab serial number",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/all-order-ids",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"all-order-ids"
					]
				}
			},
			"response": []
		},
		{
			"name": "oldest order ( next order ) based on FabLab serial number",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/fablab-next-order-id-by-serial-no/XYZ123",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"fablab-next-order-id-by-serial-no",
						"XYZ123"
					]
				}
			},
			"response": []
		},
		{
			"name": "new or updated order with updated status",
			"request": {
				"method": "POST",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "{\r\n    \"order\": {\r\n        \"id\": 101, \"date\": \"2022-04-06T11:41:08.361Z\",\r\n        \"status\": \"COMPLETED\", \"forFablabSn\": \"XYZ123\",\r\n        \"operations\": [ {\r\n            \"index\": 0, \"moduleSerialNo\": \"DFE125\",\r\n            \"submoduleSerialNo\": \"ABC987\", \"functionId\": 11,\r\n            \"parameters\": [ { \"name\": \"revolutions\", \"value\": 2, \"type\": \"integer\" } ],\r\n            \"HMIInfo\": \"Dispensing an int num of Units of salt\"\r\n        } ]\r\n    }\r\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "http://207.244.228.246:3001/api/v1/fablab-order-by-id",
					"protocol": "http",
					"host": [
						"207",
						"244",
						"228",
						"246"
					],
					"port": "3001",
					"path": [
						"api",
						"v1",
						"fablab-order-by-id"
					]
				}
			},
			"response": []
		}
	]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment