Application
Application instance
Module ID
Module logger
Module name
Connected sockets
Endpoints of the Module
Returns the init promise to know if the module init is done or not
Name of the module
Should the Application wait for the Module to initialize
Add an endpoint to the module endpoints
Endpoint to add
addEndpoint(myEndpoint)
Add multiple endpoints
addEndpoints([ endpoint1, endpoint2, ... ])
Handle /getFarmbotDailySumUp GET route: Get the farmbot records stored in the database from the farmbot API
Query:
- since
- until <timestamp> (facultative) - UNIX timestamp of an UTC value that correspond to the maximum date of the sumup
eg: /getFarmbotDailySumUp?until=1618320417 (search for entries before date 2021-04-13T13:26:57.000Z)
eg: /getFarmbotDailySumUp?since=1618319759&until=1618320417 (search for entries between dates 2021-04-13T13:15:59.000Z and 2021-04-13T13:26:57.000Z)
Response: FarmbotLogsSchema[]
// Client
const sumups = fetch('/getFarmbotDailySumUp').then((res) => res.json())
if(sumups.error) {
// Handle error
...
} else {
const todaySumup = sumups[sumups.length - 1]
console.log(todaySumup) // { date: ..., completedSequences: [ ... ], uncompletedSequences: [ ... ], errorLogs: [ ... ] }
}
Init method that is made to be overwritten with any async initialization that the server has to wait to be over before starting
A promise of the async process
await this.init()
console.log('Module initialization done.')
// Do stuff that has to wait the init
If autoInit is set on true, will run the init async method and put the result of the Promise in a variable that can be get by the application. This will allow the Application to be notified at the end of the init method of the Module If autoInit is set on false, will just put a Promise.resolve() in the init variable
Should the Application run the init method
initialize(true/false)
Listener for new client socket connection
Client socket
// Application
onSocketJoin((socket) => {
this._modules.forEach((module) => {
module.onSocketJoin(socket)
})
})
// MyModule
public onSocketJoin(socket) {
console.log(`Socket ${socket.id} joined`)
}
// index.ts
const app = new Application({...})
...
app.registerModule(MyModule)
...
// When a socket joins the server
// console: "Socket xZicnuePG5WehCSKAAAB joined"
Listener for disconnected client sockets
Client socket
// Application
onSocketJoin((socket) => {
...
socket.on('disconnected', (socket) => {
this.modules.forEach((module) => {
module.onSocketLeave(socket)
})
})
})
// MyModule
public onSocketLeave(socket) {
console.log(`Socket ${socket.id} leaved`)
}
// index.ts
const app = new Application({...})
...
app.registerModule(MyModule)
...
// When a socket leaves the server
// console: "Socket xZicnuePG5WehCSKAAAB leaved"
Register a task
Schedule of the task: Date, Moment or cron schedule
Action the will be run on schedule
Does auto start (default: true)
The task
export class MyModule extends Module {
constructor(app: Application) {
...
// Perform task every day at 10h00
this.registerTask('* * 10 * * *', this.performMyTask.bind(this), true)
}
public async performMyTask() {
...
}
}
Set the wait flag to the given value
New wait flag value
setWait(true/false)
Fetch the farmbot logs from the API and store the sumup to the database
Generated using TypeDoc
Allow farmbot daily logs sumup fetching