MK4


ist bestellt mit Enclosure

Informationen

Prusa Blog :

23.3.2023


OctoPrint

Hardware:

Raspberry PI 4b
Hyperpixel 4

/boot/config.txt

dtoverlay=vc4-kms-dpi-hyperpixel4
dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

sudo nano /usr/share/X11/xorg.conf.d/90-monitor.conf

Section "Monitor"
 Identifier "DPI-1"
 Option "Rotate" "right"
EndSection



ESP 32 Cam with Prusa Connect


please add you wifi to ssid + password

The token and fingerprint you can get view browser developer tools
Just add a camera to your printer in prusa connect, click on the QR code. Open Dev Tools -> Network Tab. In the Header you will find the Token and the Fingerprint data

/*
LADERAMPE.NET

upload images to Prusa Connect via HTTP PUT
*/

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_camera.h"

const char* ssid = "";
const char* password = "";

String token = "";
String fingerprint = "";

String serverName = "connect.prusa3d.com";
String serverPath = "/c/snapshot";

const int serverPort = 443;
const int timerInterval = 30000; // time between each HTTP POST image

WiFiClientSecure client;

// CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27

#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22

unsigned long previousMillis = 0; // last time image was sent

void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
Serial.begin(115200);

// WIFI
WiFi.mode(WIFI_STA);
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println();
Serial.print("ESP32-CAM IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());

camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG; // PIXFORMAT_JPEG

// init with high specs to pre-allocate larger buffers
if(psramFound()){
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 10; //0-63 lower number means higher quality
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_CIF;
config.jpeg_quality = 12; //0-63 lower number means higher quality
config.fb_count = 1;
}
// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
delay(1000);
ESP.restart();
}
client.setTimeout(5);
client.setInsecure();
client.connect(serverName.c_str(), serverPort);
uploadImage();
}

void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= timerInterval) {
uploadImage();
previousMillis = currentMillis;
}
}

String uploadImage() {
String getAll;
String getBody;

camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
delay(1000);
ESP.restart();
}
if (! client.connected()) {
Serial.println("ReConnecting to server: " + serverName);
client.connect(serverName.c_str(), serverPort);
}

//skip certificate validation
if (client.connected()) {
uint32_t imageLen = fb->len;
// Header
client.println("PUT " + serverPath + " HTTP/1.1");
client.println("Accept: application/json");
client.println("content-type: image/jpg");
client.println("content-length: " + String(imageLen));
client.println("Host: " + serverName);
client.println("token: " + token);
client.println("fingerprint: " + fingerprint);
client.println();

Serial.print("sending image:");
uint8_t *fbBuf = fb->buf;
size_t fbLen = fb->len;
for (size_t n=0; n<fbLen; n=n+1024) {
if (n+1024 < fbLen) {
client.write(fbBuf, 1024);
fbBuf += 1024;
}
else if (fbLen%1024>0) {
size_t remainder = fbLen%1024;
client.write(fbBuf, remainder);
}
}
Serial.print(" ... write complete");
esp_camera_fb_return(fb);
int timoutTimer = 5000;
long startTimer = millis();
boolean state = false;
while ((startTimer + timoutTimer) > millis()) {
delay(100);
while (client.available()) {
char c = client.read();
if (c == '\n') {
if (getAll.length()==0) { state=true; }
getAll = "";
}
else if (c != '\r') { getAll += String(c); }
if (state==true) { getBody += String(c); }
startTimer = millis();
}
if (getBody.length()>0) { break; }
}

Serial.println(" ... upload done!");
// Serial.println(getBody);
}
else {
getBody = "Connection to " + serverName + " failed.";
Serial.println(getBody);
}
return getBody;
Serial.println();
}