PHP code example of oriceon / mammotion

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/ */

    

oriceon / mammotion example snippets


use Oriceon\Mammotion\Facades\Mammotion;

$devices = Mammotion::devices();
$id      = $devices[0]['id'];

Mammotion::currentWork($id);      // status + battery + decoded job settings
Mammotion::start($id, 'Front yard');
Mammotion::pause($id);
Mammotion::returnToDock($id);

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

$snapshot = Mammotion::currentWork('DEV-1');

[
    'deviceId'          => 'DEV-1',
    'nickname'          => 'Yuka',
    'model'             => 'LUBA 3 AWD',
    'online'            => true,
    'status'            => MammotionDeviceStatusEnum::WORKING,
    'statusLabel'       => 'Working',
    'isWorking'         => true,
    'batteryLevel'      => 72,
    'isCharging'        => false,
    'job'               => MammotionJobContentEnum::MOWING_AND_COLLECTING,
    'jobLabel'          => 'Mowing and collecting',
    'settings'          => ['channelMode' => 'Cross stripes', 'knifeHeight' => '45 mm', …],
    'workParams'        => [ /* raw response */ ],
    'workParamsPending' => false,
    'network'           => ['usedNetwork' => '1', 'wifiRssi' => -46],
]

$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
}
bash
php artisan vendor:publish --tag=mammotion-config
php artisan vendor:publish --tag=mammotion-translations