Skip to content

Instantly share code, notes, and snippets.

@erkanarslan
Last active April 17, 2018 19:04
Show Gist options
  • Save erkanarslan/f4701ffc35c3f4671c348422958dcd8d to your computer and use it in GitHub Desktop.
Save erkanarslan/f4701ffc35c3f4671c348422958dcd8d to your computer and use it in GitHub Desktop.

General API Structure

All request endpoint urls start with api/. Data is sent and received as JSON objects. All request data is sent in the request body if not specified otherwise. You should return 200 for success responses and any code that starts with 4 for error responses.

Session Management

Login

POST : api/login

Request Data:

{
	username : string,
	password : string
}

Response Data: No data needed. Just send session id in cookie with sessionID key.

Logout (Not urgent)

POST : api/logout

Request Data: none

Response Data: none

Home Page

Get Home Page Details

GET : api/home/page

Request Data: none

Response Data:

{
	junction : string,	// Name of centris/junction
	kkc : string|null	// Name of the kkc device. Null if not connected
	time : number,		// Unix timestamp in milliseconds
	connected : boolean,	// Is centris connected to network?
	version : string,	// Centris version
	// These are for LCD screen
	phaseId : number,
	extraDuration : number,
	phaseDuration : number,
	algorithm : string,
	isSimActive : 1|0,
	signalPlanUpdatedAt : number	// Unix timestamp in milliseconds. Last time at which signal plan is updated
}

Settings

Get General Settings

GET : api/settings/general

Request Data: none

Response Data:

{
	time : number,			// Unix timestamp in milliseconds
	ntpIP : string,			// IP of the ntp server
	junctionId : string|null,
	username : string		// Device login user name
}

Set General Settings

PUT : api/settings/general

Request Data:

{
	time : number,	// Unix timestamp in milliseconds
	ntpIP : string	// IP of the ntp server
}

Response Data: none

Set Junction ID

PUT : api/settings/junction-id

Request Data:

{
	value : string	// Junction id as string
}

Response Data: none

Change Username And Password

PUT : api/settings/credentials

Request Data:

{
	username : string,
	password : string
}

Response Data: none

Get Network Settings

GET : api/settings/network

Request Data: none

Response Data:

{
	ip : string,
	netmask : string,
	gateway : string,
	apn : string,          // APN for sim card
	simUser : string,      // Sim card user name
	isSimActive : boolean,
	simHasPin : boolean,    // Shows if sim card needs a pin number to connect
	simIP : string		// IP address used by sim card
}

Set Network Settings

PUT : api/settings/network

Request Data:

{
	ip : string,
	netmask : string,
	gateway : string
}

Response Data: none

Set Sim Card Settings

PUT : api/settings/sim-card

Request Data:

{
	apn : string,
	simUser : string,
	simPassword : string
}

Response Data: none

Activate/Deactivate Sim Card

PUT : api/settings/sim-card/active

Request Data:

{
	value : boolean    // Activate if true, deactivate if false.
}

Response Data: none

Remove PIN Code

POST : api/settings/sim-card/remove-pin

Request Data:

{
	pin : string
}

Response Data: none

Configurations

Get All Configuration File Contents

GET : api/configurations

Request Data: none

Response Data:

{
	httpClient : {
		ip : string,
		port : string,
		authHeader : string	// This should contain only the auth key, no 'Bearer ' part.
	}
}

Set Http Client Settings

This end point sets only three important properties on httpclient.conf file.

PUT : api/configurations/http-client

Request Data:

{
	ip : string,
	port : string,
	authHeader : string
}

Set Configuration File Contents

This end point can set content of any configuration file. You can get which file to update from url.

PUT : api/configurations/file/:fileName

fileName is httpClient for http client configuration file. Others will be implemented later.

Request Data:

{
	// Same as the one sent in get request
}

Get Phase Map

GET : api/configurations/phase-map

Request Data: none

Response Data: A map of phase numbers to groups

{ [phaseNo : number] : string }

Example:

{
	"1" : "1-2-3",
	"2" : "4-5-6",
	"3" : "7"
}

Set Phase Map

PUT : api/configurations/phase-map

Request Data: Same as the data received above

Device Management

Get Management Page Details

GET : api/management/page

Request Data: none

Response Data:

{
	currentAlgorithm : string,	// Name of the current algorithm
	algorithmList : sting[],	// List of all algorithm names
	services : [{			// List of service details
		name : string,		// Name of the service
		autoStart : boolean,	// Does this service automatically start on device boot?
		isRunning : boolean,
		canBeEnabled : boolean	// Can user enable/run this service from centris ui?
	}],
	numberOfPhases : number		// How many phases are there in this centris? (Do we need this? Would it be enough for me to show the users from 1 to 6. They already know which phase to work on.)
}

Change Algorithm

PUT : api/management/algorithm

Request Data:

{
	algorithm : string|'none'	// Name of the algoritm to run. If 'none', don't run any algorithm.
}

Response Data: none

Static Duration Request

POST : api/management/static-duration

Request Data:

{
	phase : number,		// No of the phase
	duration : number	// Time in seconds
}

Response Data: none

Manually Triggering a Phase

POST : api/management/manual-trigger

Request Data:

{
	phase : number	// No of the phase
}

Response Data: none

Start/Stop A Service

Service name is specified in the url.

PUT : api/management/services/:serviceName/running

Request Data:

{
	value : boolean    // Start if true, stop if false.
}

Response Data: none

Upload New Firmware

Uploads given file as firmware

PUT : api/firmware

Request Data:

Data format is FormData. File is sent in file property.

Response Data: none

Restart Centris

It would be better if you send the response first, then restart the device. Otherwise I cannot know if operation failed or succeeded.

POST : api/management/restart

Request Data: none

Response Data: none

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