Skip to content

Switch to apikey, from access token #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "viam_flutter_provisioning_widget",
"request": "launch",
"type": "dart"
},
{
"name": "viam_flutter_provisioning_widget (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "viam_flutter_provisioning_widget (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "bluetooth_provisioning",
"cwd": "example/bluetooth_provisioning",
"request": "launch",
"type": "dart"
},
{
"name": "bluetooth_provisioning (profile mode)",
"cwd": "example/bluetooth_provisioning",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "bluetooth_provisioning (release mode)",
"cwd": "example/bluetooth_provisioning",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "hotspot_provisioning",
"cwd": "example/hotspot_provisioning",
"request": "launch",
"type": "dart"
},
{
"name": "hotspot_provisioning (profile mode)",
"cwd": "example/hotspot_provisioning",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "hotspot_provisioning (release mode)",
"cwd": "example/hotspot_provisioning",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class _ConnectHotspotPrefixScreenState extends State<ConnectHotspotPrefixScreen>
@override
void initState() {
super.initState();
_viam = Viam.withAccessToken(Consts.accessToken);
// you MUST create the robot before connecting to the hotspot
// once connected to the hotspot you can communicate with the machine, but will not have interet access
_createRobot();
_initViam();
}

@override
Expand All @@ -49,10 +46,21 @@ class _ConnectHotspotPrefixScreenState extends State<ConnectHotspotPrefixScreen>
super.dispose();
}

Future<void> _initViam() async {
try {
_viam = await Viam.withApiKey(Consts.apiKeyId, Consts.apiKey);
// you MUST create the robot before connecting to the hotspot
// once connected to the hotspot you can communicate with the machine, but will not have interet access
_createRobot();
} catch (e) {
debugPrint('Error initializing Viam: $e');
}
}

Future<void> _createRobot() async {
final location = await _viam.appClient.createLocation(Consts.organizationId, 'TEST-${Random().nextInt(1000)}');
final location = await _viam.appClient.createLocation(Consts.organizationId, 'test-location-${Random().nextInt(1000)}');
final String robotName = "tester-${Random().nextInt(1000)}";
debugPrint('robotName: $robotName');
debugPrint('robotName: $robotName, locationId: ${location.name}');
final robotId = await _viam.appClient.newMachine(robotName, location.id);
_robot = await _viam.appClient.getRobot(robotId);
_mainPart = (await _viam.appClient.listRobotParts(robotId)).firstWhere((element) => element.mainPart);
Expand Down
8 changes: 5 additions & 3 deletions example/hotspot_provisioning/lib/consts.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Consts {
static const String hotspotPrefix = 'hotspot';
static const String hotspotPassword = 'password';
static const String hotspotPrefix = '';
static const String hotspotPassword = '';

static const String apiKeyId = '';
static const String apiKey = '';

static const String accessToken = '';
static const String organizationId = '';
}
2 changes: 1 addition & 1 deletion example/hotspot_provisioning/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
git:
url: https://github.com/viamrobotics/plugin_wifi_connect
ref: 0.0.2
viam_sdk: 0.5.1
viam_sdk: 0.6.1

dev_dependencies:
flutter_test:
Expand Down