As it is now of OctoPrintAPI (V1.1.15) it is only possible to initialize it before setup.
This makes problems for dynamic variables.
But i changed the source so that OctoPrintAPI will work from within setup now with success.
Here is what needs to be changed:
In OctoPrintAPI.h
class OctoprintApi {
public:
//OctoprintApi(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey);//DigiHzData removed.
//OctoprintApi(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey);//DigiHzData removed.
OctoprintApi(Client &client);//DigiHzData added.
void begin(IPAddress octoPrintIp, int octoPrintPort, String apiKey);//DigiHzData added.
void begin(char *octoPrintUrl, int octoPrintPort, String apiKey);//DigiHzData added.
...
In OctoPrintAPI.cpp
#include "OctoPrintAPI.h"
#include "Arduino.h"
OctoprintApi::OctoprintApi(Client &client){//DigiHzData added.
_client = &client;//DigiHzData added.
}//DigiHzData added.
/** OctoprintApi()
- IP address version of the client connect function
- */
//OctoprintApi::OctoprintApi(Client &client, IPAddress octoPrintIp, int octoPrintPort, String apiKey) {//DigiHzData removed.
void OctoprintApi::begin(IPAddress octoPrintIp, int octoPrintPort, String apiKey) {//DigiHzData added.
//_client = &client;//DigiHzData removed.
_apiKey = apiKey;
_octoPrintIp = octoPrintIp;
_octoPrintPort = octoPrintPort;
_usingIpAddress = true;
}
/** OctoprintApi()
- Hostname version of the client connect function
- */
//OctoprintApi::OctoprintApi(Client &client, char *octoPrintUrl, int octoPrintPort, String apiKey) {//DigiHzData removed.
void OctoprintApi::begin(char *octoPrintUrl, int octoPrintPort, String apiKey) {//DigiHzData added.
//_client = &client;//DigiHzData removed.
_apiKey = apiKey;
_octoPrintUrl = octoPrintUrl;
_octoPrintPort = octoPrintPort;
_usingIpAddress = false;
}
/** GET YOUR ASS TO OCTOPRINT...
*
After these changes has been made, then you initiate OctoPrintApi before setup with:
OctoprintApi api(client);
And in setup you do either:
api.begin(ip, octoprint_httpPort, octoprint_apikey);//If using IP address
OR
api.begin(octoprint_host, octoprint_httpPort, octoprint_apikey);//If using hostname.
This way, we can pull ip, octoprint_host, octoprint_httpPort and octoprint_apikey from eeprom or sd card.