1. Go to this page and download the library: Download oriceon/mammotion library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Mammotion::accessToken(); // cached token
Mammotion::accessToken(true); // force a new one
Mammotion::forgetToken(); // drop the cached tokens
use Oriceon\Mammotion\Facades\Mammotion;
use Oriceon\Mammotion\MammotionClient;
Mammotion::devices();
app(MammotionClient::class)->devices();
(new MammotionClient(clientId: '…', clientSecret: '…'))->devices();
Mammotion::devices(); // every mower bound to the account
Mammotion::device('DEV-1'); // raw detail: status, battery, network, firmware
Mammotion::status('DEV-1'); // MammotionDeviceStatusEnum|null
Mammotion::isOnline('DEV-1'); // bool
Mammotion::batteryLevel('DEV-1'); // int|null
$params = Mammotion::workParams('DEV-1');
Mammotion::workParamsArePopulated($params); // false for an empty acknowledgement
// Ask a few times, in case the backend serves the mower's later report from cache:
Mammotion::workParamsPolled('DEV-1', attempts: 4, delayMs: 2000);
Mammotion::start('DEV-1', 'Front yard'); // runs a task created in the Mammotion app
Mammotion::startImmediately('DEV-1'); // mow now, no plan
Mammotion::pause('DEV-1');
Mammotion::resume('DEV-1');
Mammotion::stop('DEV-1'); // stops and cancels the task
Mammotion::returnToDock('DEV-1');
Mammotion::cancelReturn('DEV-1');
// Or the generic form:
Mammotion::action('DEV-1', MammotionActionEnum::START, 'Front yard');
use Oriceon\Mammotion\Enums\MammotionSubscriptionPropertyEnum as Property;
Mammotion::subscribeDevice('DEV-1'); // basic telemetry set
Mammotion::subscribeDevice('DEV-1', [Property::WORK_PROGRESS, Property::COORDINATES]);
Mammotion::subscribe([
'DEV-1' => [Property::DEVICE_STATUS, Property::BATTERY_PERCENT],
'DEV-2' => Property::telemetry(),
]);
use Oriceon\Mammotion\Exceptions\MammotionApiException;
try {
Mammotion::pause('DEV-1');
}
catch (MammotionApiException $e) {
$e->getMessage();
$e->apiCode; // application code, e.g. 4001
$e->httpStatus; // HTTP status
$e->requestId; // Mammotion request id, useful for support
}