-
Notifications
You must be signed in to change notification settings - Fork 21
/
ArduinoJson.ino
116 lines (99 loc) · 2.32 KB
/
ArduinoJson.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <ArduinoJson.h>
#include <GoProControl.h>
#include "Secrets.h"
// Allocate the JSON document
StaticJsonDocument<4000> status;
StaticJsonDocument<1000> media; // media list
GoProControl gp(GOPRO_SSID, GOPRO_PASS, CAMERA);
void setup()
{
Serial.begin(115200);
//gp.enableDebug(&Serial);
}
void compute_status()
{
// Deserialize the JSON document
DeserializationError error = deserializeJson(status, gp.getStatus());
// Test if parsing succeeds.
if (error)
{
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
// Print values
// To understand these values see the camera status file, for example for MAX:
// https://github.com/KonradIT/goprowifihack/blob/master/MAX/CameraStatus.md
byte battery = status["status"]["1"];
byte charge = status["status"]["2"];
byte mode = status["settings"]["1"];
byte vr = status["settings"]["2"];
Serial.print("Battery: ");
Serial.println(battery);
Serial.print("Charge: ");
Serial.println(charge);
Serial.print("Mode: ");
Serial.println(mode);
Serial.print("Video Resolution: ");
Serial.println(vr);
}
void compute_mediaList()
{
// Deserialize the JSON document
DeserializationError error = deserializeJson(media, gp.getMediaList());
// Test if parsing succeeds.
if (error)
{
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
// Print values.
const char *id = media["id"];
const char *folder = media["media"][0]["d"];
JsonArray array = media["media"][0]["fs"];
byte pic = array.size();
Serial.print("ID: ");
Serial.println(id);
Serial.print("Folder: ");
Serial.println(folder);
Serial.print("Number of pic: ");
Serial.println(pic);
}
void loop()
{
char in = 0;
if (Serial.available() > 0)
{
in = Serial.read();
}
switch (in)
{
default:
break;
// Connect
case 'b':
if (gp.begin() == 1)
{
Serial.println("Connected!");
}
break;
case 'c':
Serial.print("Connected: ");
Serial.println(gp.isConnected() == true ? "Yes" : "No");
break;
case 's':
Serial.println("Status");
compute_status();
break;
case 'm':
Serial.println("Media list");
compute_mediaList();
break;
case 'x':
Serial.println("Closing");
gp.end();
break;
}
gp.keepAlive();
}