Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // mill kommandoer
- char settPower[] = {0x00, 0x10, 0x06, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Powertoggle er pos 5
- char settTemp[] = {0x00, 0x10, 0x08, 0x00, 0x43, 0x04, 0x0A, 0x01, 0x12, 0x02}; //, 0x20, 0x03, 0x0A}; // temperatursetting er pos 8
- sendCmd(settPower, sizeof(settPower), 0x01); // På
- sendCmd(settPower, sizeof(settPower), 0x00); // Av
- sendCmd(settTemp, sizeof(settTemp), temperatur); // 5-35, men mills mikrokontroller aksepterer andre verdier. ;)
- ---- Utklipp fra publiseringsfunksjon (mill kontroller -> mqtt ut) ---
- if (receivedChars[4] == 0xC9 ) { // Filtrer ut unødig informasjon
- if (receivedChars[6] != 0 ) {
- settpunkt = receivedChars[6], DEC;
- }
- if (receivedChars[7] != 0 ) {
- temperatur = receivedChars[7], DEC;
- }
- if (strstr (power, "On")) {
- if (receivedChars[11] == 0x00 ) {
- sprintf(aktiv, "Idle");
- } else if (receivedChars[11] == 0x01 ) {
- sprintf(aktiv, "Heat");
- }
- }
- --- Seriedata inn funksjon --------------
- void recvWithStartEndMarkers() {
- static boolean recvInProgress = false;
- static byte ndx = 0;
- char startMarker = 0x5A;
- char endMarker = 0x5B;
- char rc;
- while (Serial.available() > 0 && newData == false) {
- rc = Serial.read();
- if (recvInProgress == true) {
- if (rc != endMarker) {
- receivedChars[ndx] = rc;
- ndx++;
- if (ndx >= numChars) {
- ndx = numChars - 1;
- }
- }
- else {
- recvInProgress = false;
- ndx = 0;
- newData = true;
- }
- }
- else if (rc == startMarker) {
- recvInProgress = true;
- }
- }
- }
- --- Seriedata ut til mill mikrokontroller ---
- void sendCmd(char* arrayen, int len, int kommando) {
- if (arrayen[4] == 0x43){ // Temperatur
- arrayen[8] = kommando;
- }
- if (arrayen[4] == 0x47){ // Power av/på
- arrayen[5] = kommando;
- arrayen[len] = (byte)0x00; // Padding..
- }
- char crc = checksum(arrayen, len+1);
- Serial.write((byte)0x5A); // Startbyte
- for (int i = 0; i < len+1; i++) { // Beskjed
- Serial.write((byte)arrayen[i]);
- }
- Serial.write((byte)crc); // Kontrollbyte
- Serial.write((byte)0x5B); // Stoppbyte
- }
- --- Funksjon for summering av kontrollbyte ---
- unsigned char checksum(char *buf, int len) {
- unsigned char chk = 0;
- for ( ; len != 0; len--) {
- chk += *buf++;
- }
- return chk;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement