P1 poort slimme meter – Telegram uitlezen met Python
Er zijn talloze scripts op het internet te vinden om “eenvoudig” telegrammen uit te lezen afkomstig van de P1 poort, …
P1 poort slimme meter – Telegram uitlezen met Python Lees meer »
Er zijn talloze scripts op het internet te vinden om “eenvoudig” telegrammen uit te lezen afkomstig van de P1 poort, …
P1 poort slimme meter – Telegram uitlezen met Python Lees meer »
Bron: jantenhove @ Github Software for the ESP2866 that sends P1 smart meter data to Domoticz (with CRC checking and OTA …
P1 poort slimme meter – Data naar Domoticz (ESP8266) Lees meer »
Bron: woutertp1Â @ Github Smart-meter-P1 ============== Readout of Dutch smart meter P1-port using Arduino and logging to EmonCMS. What do you …
P1 poort slimme meter – Data naar EmonCMS (Arduino) Lees meer »
Bron: willem4ever @ Github
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
#include <Time.h> #include <SPI.h> #include <EEPROM.h> #include <Dhcp.h> #include <Dns.h> #include <Ethernet.h> #include <EthernetClient.h> #include <EthernetServer.h> #include <EthernetUdp.h> #include <util.h> #include <PubSubClient.h> struct obis { byte a; byte b; byte c; byte d; byte e; byte f; }; byte mac[6] = { 0x90, 0xA2, 0xDA, 0x0d, 0x5c, 0x21 }; IPAddress ip(192,168,223,24); IPAddress gateway(192,168,223, 5); IPAddress subnet(255, 255, 255, 128); unsigned int localPort = 123; // local port to listen for UDP packets IPAddress dhcpNtp(192,168,223,9); // default, will take ip from dhcp server byte broker[] = { 192,168,223,7}; const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets // An EthernetUDP instance to let us send and receive packets over UDP EthernetUDP Ntp; PubSubClient client(broker, 1883, callback); unsigned long getNtpTime(); byte GetObis (char *p, struct obis *po); time_t pminute = 0; // once a minute time_t psecond = 0; const long timeZoneOffset = 0L; // set this to the offset in seconds to your local time; //const int pir = 7; //int pirstatus = 0; //int lightstatus = 0; char topic[64]; char Value[10][12]; char buffer[64]; char scratch[20]; byte bIndex; long datagrams; const char *message[] = { "powerusage1","powerusage2","powerdelivery1","powerdelivery2","powerrate","powerusagec","powerdeliveryc","gasusage"}; byte GetObis (char *p, struct obis *po) { // return index to delimeter hit byte i,a; po->a = po->b = po->c = po->d = po->e = po->f = 0xff; // clear obis struct i = a = 0; while (isdigit(p[i]) || p[i] == '-' || p[i] == ':' || p[i] == '.' || p[i] == '*') { // Escape on any non valid OBIS character if (isdigit(p[i])) { if (a) { a = a*10+p[i] - 0x30; } else a = p[i] - 0x30; } if (p[i] == '-') { po->a = a; a=0; } else if (p[i] == ':') { po->b = a; a=0; } else if (p[i] == '.' && po->c == 0xff) { po->c = a; a=0; } else if (p[i] == '.' && po->d == 0xff) { po->d = a; a=0; } else if (p[i] == '*' ) { po->e = a; a=0; } i++; } // We bumped into a non valid character, determine the last obis field (C & D are mandatory) if (po->d == 0xff) { // D po->d = a; } else if (po->e == 0xff) { // E po->e = a; } else if (po->f == 0xff) { // F po->f = a; } return i; } byte CompareObis (obis *po, byte a,byte b,byte c,byte d, byte e,byte f) { return (po->a == a && po->b == b && po->c == c && po->d == d && po->e == e && po->f == f); } // Extracts string from a single line and return index to the next value (when available) or '0' on EOL byte GetString (char *s,char *d) { byte i; i=0; while (s[i] != ')' && s[i] != 0) { if (s[i] != '(') { *d = s[i]; d++; } *d=0; i++; // Advance to next } // return ( s[i] == ')' && s[i+1] == '(' ? i+1 : 0 ); // 0 or index to next value } // Extracts float from a single line and return index to the next value (when available) or '0' on EOL byte GetFloat (char *s,char *d) { byte i; i=0; while (s[i] != ')' && s[i] != 0) { if (s[i] != '(') { if (s[i] == '*') *d=0; // Terminate on unit, but keep for reference else *d = s[i]; d++; } *d=0; i++; // Advance to next } // return ( s[i] == ')' && s[i+1] == '(' ? i+1 : 0 ); // 0 or index to next value } void callback(char* topic, byte* payload,unsigned int length) { ;// handle message arrived } void publish(char *xtopic,char *payload) { if(xtopic[0] == '/') sprintf (topic,"%s/%x%x%x",xtopic,mac[3],mac[4],mac[5]); else sprintf (topic,"/sensor/%x%x%x/%s",mac[3],mac[4],mac[5],xtopic); client.publish(topic, payload); } void setup() { int i; pinMode(2,INPUT); pinMode(A2,OUTPUT); digitalWrite(A2,1); Serial.begin(9600); UCSR0C = (UCSR0C & B11000001 ) | B00000100 | B00100000; // 7 bit even parity //for (i=0;i<5;i++) // EEPROM.write(i, mac[i]); for (i=0;i<5;i++) mac[i]=EEPROM.read(i); Serial.println(dhcpNtp); // start Ethernet and UDP if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); Ethernet.begin(mac,ip,subnet); } if (Ethernet.ntpServerIP()) { dhcpNtp = Ethernet.ntpServerIP(); } Serial.println(dhcpNtp); // Serial.print("My IP address: "); ip = Ethernet.localIP(); Ntp.begin(localPort); setSyncProvider(getNtpTime); while(timeStatus()== timeNotSet) ; // wait until the time is set by the sync provider // create unique client name based on mac address sprintf(buffer,"smarty%x%x%x",mac[3],mac[4],mac[5]); i = client.connect(buffer); ltoa (now(),scratch,10); publish("hello",scratch); bIndex = 0; datagrams = 0; } void loop() { unsigned long t = now(); int a; struct obis po; digitalWrite(A2,!digitalRead(2)); // Check for serial input if (Serial.available() > 0) { // read the incoming byte: a = Serial.read(); if (a != 0x020 || a != '\r') buffer[bIndex] = a; if (a == '\n') { buffer[bIndex]=0; if (buffer[0] == '/') { // MeterID ; } else if (buffer[0] == '!') { // End of Message // Publish our findings //long x = micros(); int i = 0; for (i=0;i<8;i++) { publish((char*)message[i],Value[i]); } datagrams++; //x = micros() - x; //sprintf(buffer,"%ld us",x); //publish("Timer/Elapsed",buffer); } else if (bIndex > 2) { //ignore empty lines int i = GetObis(buffer, &po); // 1-0:1.8.1(00180.726*kWh) powerusage1 if (CompareObis(&po,1,0,1,8,1,255)) { i = GetFloat(&buffer[i],Value[0]); //publish("Powerusage1",Value); } //1-0:1.8.2(00001.416*kWh) powerusage2 else if (CompareObis(&po,1,0,1,8,2,255)) { i = GetFloat(&buffer[i],Value[1]); //publish("Powerusage2",Value); } // 1-0:2.8.1(00000.000*kWh) else if (CompareObis(&po,1,0,2,8,1,255)) { i = GetFloat(&buffer[i],Value[2]); //publish("Powerdelivery1",Value); } // 1-0:2.8.2(00000.000*kWh) else if (CompareObis(&po,1,0,2,8,2,255)) { i = GetFloat(&buffer[i],Value[3]); //publish("Powerdelivery2",Value); } // 0-0:96.14.0(0001) else if (CompareObis(&po,0,0,96,14,0,255)) { i = GetString(&buffer[i],Value[4]); //publish("PowerTariff",Value); } // 1-0:1.7.0(0000.42*kW) else if (CompareObis(&po,1,0,1,7,0,255)) { i = GetFloat(&buffer[i],Value[5]); //publish("Powerusage",Value); } // 1-0:2.7.0(0000.00*kW) else if (CompareObis(&po,1,0,2,7,0,255)) { i = GetFloat(&buffer[i],Value[6]); //publish("Powerdelivery",Value); } // Invalid Obis returns with po.d = 0 ... else if (CompareObis(&po,255,255,255,0,255,255)) { i = GetFloat(&buffer[i],Value[7]); //publish("Gasusage",Value); } } bIndex=0; } else { if (bIndex < 64) bIndex++; } } if( t % 60 == 0 && t != pminute) { //update the display only if the time has changed pminute = t; psecond = t; ltoa (t,scratch,10); publish("timestamp", scratch); ltoa (datagrams,scratch,10); publish("datagrams", scratch); Ethernet.maintain(); } client.loop(); } unsigned long getNtpTime () { int iBytes; sendNTPpacket(dhcpNtp); // send an NTP packet to a time server // Serial.println("#1"); // wait for a reply / timeout after 10 seconds iBytes = 0; while (Ntp.parsePacket() != 48 && iBytes < 2000) { iBytes++; delay(5); } // Serial.println("#2"); if (Ntp.available() == 48) { Serial.print("time synched in "); Serial.print(iBytes*5); Serial.println(" milliseconds"); // Ntp.read(packetBuffer,8); // dump header Ntp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer // The timestamp starts at byte 40 of the received packet and is four bytes, // or two words, long. First, esxtract the two words: unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): unsigned long secsSince1900 = highWord << 16 | lowWord; const unsigned long seventyYears = 2208988800UL - timeZoneOffset; unsigned long epoch = secsSince1900 - seventyYears; return epoch; } else { //Serial.print (Ntp.available()); //Serial.println(" - No NTP packet received"); return 0; } } // send an NTP request to the time server at the given address void sendNTPpacket(IPAddress ntpServer) { // set all bytes in the buffer to 0 memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) packetBuffer[0] = 0b11100011; // LI, Version, Mode packetBuffer[1] = 0; // Stratum, or type of clock packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision // 8 bytes of zero for Root Delay & Root Dispersion packetBuffer[12] = 49; packetBuffer[13] = 0x4E; packetBuffer[14] = 49; packetBuffer[15] = 52; // all NTP fields have been given values, now // you can send a packet requesting a timestamp: Ntp.beginPacket(ntpServer, 123); Ntp.write( packetBuffer,NTP_PACKET_SIZE); Ntp.endPacket(); } |
Bron: dovadi @ Github Dit is een voorbeeldscript om P1  gegevens weg te schrijven naar emonWeb.org ReadP1 Reading P1 Companion Standard …
P1 poort slimme meter – Data naar emonWeb.org (Arduino) Lees meer »
Dit is een voorbeeldscript van “Zonnig Breda” om P1 Â gegevens weg te schrijven naar COSM.com
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
#include <AltSoftSerial.h> #define maxRunTime 600000L #define UPDATE_COSM 1 #define SDLOG 0 #define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below) // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: #define FIXEDSERVER 1 // set to 1 to to use the numeric server #define etherPin 10 //pin to be used for the ethernet card #if UPDATE_COSM #include <EtherCard.h> #endif #if SDLOG #include <SD.h> #endif // AltSoftSerial always uses these pins: // // Board Transmit Receive PWM Unusable // ----- -------- ------- ------------ // Teensy 2.0 9 10 (none) // Teensy++ 2.0 25 4 26, 27 // Arduino Uno 9 8 10 // Arduino Mega 46 48 44, 45 // Wiring-S 5 6 4 // Sanguino 13 14 12 AltSoftSerial altSerial; //int pMode = 0; #define BUFSIZE 75 char buffer[BUFSIZE]; int bufpos = 0; int Pos = 0; #define StartChar = '/'; #define StopChar = '!'; long PowerUsage = 0; long PowerSolar = 0; float GasMeter = 0; float GasUsage = 0; long m1 = 0; long m2 = 0; long m3 = 0; long m4 = 0; bool readnextLine = false; #define MeterInterval 60000 // Send the meter values only once per 60s unsigned long previousMillis; bool sendMeter = true; #if UPDATE_COSM // change these settings to match your own setup #define APIKEY "ENTER YOUR KEY HERE" // your cosm api key #define FEED "ENTER FEED" // your feed ID #define USERAGENT "Cosm Arduino Example (62918)" // user agent is the project name // ethernet interface mac address static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x36 }; #if STATIC // ethernet interface ip address static byte myip[] = { 192,168,3,160 }; // gateway ip address static byte gwip[] = { 192,168,3,1 }; //dns server static byte dnsip[] = { 8,8,8,8 }; #endif #if FIXEDSERVER static byte hisip[] = { 216,52,233,122 }; #else char website[] PROGMEM = "api.pachube.com"; #endif byte Ethernet::buffer[265]; //byte Ethernet::buffer[250]; //uint32_t timer; Stash stash; #endif #include <MemoryFree.h> void setup() { Serial.begin(9600); Serial.println(F("Energie reading Begins...")); //memory friendly altSerial.begin(9600); #if SDLOG Serial.println(F("Initializing SD card...")); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. // pinMode(10, OUTPUT); // digitalWrite(10, HIGH); // digitalWrite(4, HIGH); if (!SD.begin(4)) { Serial.println(F("initialization failed!")); return; } #endif checkmem(); #if UPDATE_COSM netsetup(); #endif checkmem(); } void loop() { // forced realod after 10 min run time impl if(millis() > maxRunTime ) { softReset(); } #if UPDATE_COSM ether.packetLoop(ether.packetReceive()); // int tt = ether.packetLoop(ether.packetReceive()); // if (tt) Serial.println (tt); #endif if (millis() > (previousMillis + MeterInterval) ) { sendMeter = true ; previousMillis = millis(); } char c; if (Serial.available()) { c = Serial.read(); } if (altSerial.available()) { c = altSerial.peek(); if (c == '/' ){ //StartChar){ checkmem(); } // we've loaded a line. Now parse the values if (read2Line()){ Serial.print(buffer); long tl = 0; long tld =0; if (sendMeter) { //Meter //1-0:1.8.1(00391.000*kWh) if (sscanf(buffer,"1-0:1.8.1(%ld%.%ld%*s" , &tl, &tld) >0 ) //) { m1 = tl * 1000 + tld;} if (sscanf(buffer,"1-0:1.8.2(%ld%.%ld%*s" , &tl, &tld) >0 ) //) { m2 = tl * 1000 + tld;} if (sscanf(buffer,"1-0:2.8.1(%ld%.%ld%*s" , &tl, &tld) >0 ) //) { m3 = tl * 1000 + tld;} if (sscanf(buffer,"1-0:2.8.2(%ld%.%ld%*s" , &tl, &tld) >0 ) //) { m4 = tl * 1000 + tld;} } //sendmeter if (readnextLine){ if (sscanf(buffer,"(%ld.%ld%*s" , &tl, &tld) >0 ) { //) //(00127.969) GasMeter = float ( tl * 1000 + tld ) / 1000 ; //(00127.969) readnextLine = false; }} //gas 0-1:24.3.0 if (sscanf(buffer,"0-1:24.3.0(%6ld%4ld%*s" , &tl, &tld) > 0 ) { //) Serial.print (F("Gasreading time ")); Serial.print (tl) ; Serial.print (F("-")); Serial.println (tld) ; readnextLine = true; } // Consumption if (sscanf(buffer,"1-0:1.7.0(%ld.%ld%*s" , &tl , &tld) >0 ) //) { PowerUsage = tl * 1000 + tld * 10;} // Supply // 1-0:2.7.0(0000.00*kW) if (sscanf(buffer,"1-0:2.7.0(%ld.%ld%*s" , &tl , &tld) >0 ) //) { PowerSolar = tl * 1000 + tld * 10;} //we're done if (buffer[0] == '!' ) { checkmem(); GasUsage = GasMeter; printData(); checkmem(); #if UPDATE_COSM // SendData (GasUsage,PowerUsage,PowerSolar); SendData(); #endif if (sendMeter){ #if UPDATE_COSM // SendDataM (GasMeter,m1,m2,m3,m4); SendDataM (); #endif sendMeter = false; } checkmem(); #if SDLOG // SaveData(GasUsage,PowerUsage,PowerSolar); SaveData(); #endif checkmem(); } } } } void printData(){ Serial.print(F("Power : ")); Serial.println(PowerUsage); Serial.print(F("PowerSolar : ")); Serial.println(PowerSolar); Serial.print(F("GAS : ")); Serial.println(GasUsage,3 ); Serial.println(F("*Meters*")); Serial.println(m1); Serial.println(m2); Serial.println(m3); Serial.println(m4); } void checkmem(){ Serial.print(F("FreeMemory()=")); Serial.println(freeMemory()); } /* float ConvertStr(String TheNumber){ char bufx[TheNumber.length()+2]; TheNumber.toCharArray(bufx,TheNumber.length()+1); return float(atof(bufx)); } */ bool read2Line() { char c; // bufpos = 0; // buffer[0] = '\0'; c = altSerial.read(); if (bufpos + 1 < BUFSIZE) { buffer[bufpos] = c&127; bufpos++; } else { // return the partial line Serial.println(F("************************")); Serial.println(F("**Readline Buffer Full**")); Serial.println(F("************************")); buffer[bufpos] = '\0'; bufpos = 0; return true; } if (c == '\n'){ buffer[bufpos] = '\0'; bufpos = 0; return true; } else return false; } #if UPDATE_COSM void netsetup(){ Serial.println(F("\n[webClient]")); if (ether.begin(sizeof Ethernet::buffer, mymac,etherPin) == 0) Serial.println(F("Failed to access Ethernet controller")); #if STATIC ether.staticSetup(myip, gwip); // use the GoogleDNS ether.copyIp(ether.dnsip, dnsip); #else if (!ether.dhcpSetup()) Serial.println(F("DHCP failed")); #endif ether.printIp("IP: ", ether.myip); ether.printIp("GW: ", ether.gwip); ether.printIp("DNS: ", ether.dnsip); #if FIXEDSERVER ether.copyIp(ether.hisip, hisip); #else if (!ether.dnsLookup(website)) Serial.println(F("DNS failed")); #endif ether.printIp("SRV: ", ether.hisip); } #endif #if UPDATE_COSM void SendData(){ // by using a separate stash, // we can determine the size of the generated message ahead of time byte sd = stash.create(); stash.print("G,"); stash.println(GasUsage,3); stash.print("P,"); stash.println(PowerUsage); stash.print("S,"); stash.println(PowerSolar); stash.save(); checkmem(); // generate the header with payload - note that the stash size is used, // and that a "stash descriptor" is passed in as argument using "$H" // Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n" Stash::prepare(PSTR("PUT /v2/feeds/$F.csv HTTP/1.0" "\r\n" "Host: api.pachube.com" "\r\n" "X-PachubeApiKey: $F" "\r\n" "Content-Length: $D" "\r\n" "\r\n" "$H"), // website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd); PSTR(FEED), PSTR(APIKEY), stash.size(), sd); checkmem(); // send the packet - this also releases all stash buffers once done ether.tcpSend(); checkmem(); } #endif #if UPDATE_COSM void SendDataM(){ // by using a separate stash, // we can determine the size of the generated message ahead of time byte sd = stash.create(); if (GasMeter != 0){ stash.print("GM,"); stash.println(GasMeter,3); } m1 = m1+2; stash.print("m1,"); stash.println(float (m1/1000),3); stash.print("m2,"); stash.println(float (m2/1000),3); stash.print("m3,"); stash.println(float (m3/1000),3); stash.print("m4,"); stash.println(float (m4/1000),3); stash.save(); // generate the header with payload - note that the stash size is used, // and that a "stash descriptor" is passed in as argument using "$H" // Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n" Stash::prepare(PSTR("PUT /v2/feeds/$F.csv HTTP/1.0" "\r\n" "Host: api.pachube.com" "\r\n" "X-PachubeApiKey: $F" "\r\n" "Content-Length: $D" "\r\n" "\r\n" "$H"), // website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd); PSTR(FEED), PSTR(APIKEY), stash.size(), sd); // send the packet - this also releases all stash buffers once done // Serial.print("sending Size : "); // Serial.print(stash.size()); if (( stash.size() <= 0) || (stash.size() > 400 )){ } else{ ether.tcpSend(); } } #endif #if SDLOG //void SaveData(float value1, long value2 ,long value3){ void SaveData(){ char dataString[30]=""; checkmem(); sprintf (dataString,"%ld,%ld,%ld,%ld",millis(),long(GasMeter/1000),PowerUsage,PowerSolar); /* // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. */ checkmem(); Serial.println(dataString); checkmem(); File dataFile = SD.open("datalog.txt", FILE_WRITE); checkmem(); // if the file is available, write to it: if (dataFile) { dataFile.println(dataString); dataFile.close(); // print to the serial port too: } // if the file isn't open, pop up an error: else { Serial.println(F("error opening datalog.txt")); } checkmem(); } #endif /* char *ftoa(char *a, double f, int precision) { long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000}; char *ret = a; long heiltal = (long)f; itoa(heiltal, a, 10); while (*a != '\0') a++; *a++ = '.'; long desimal = abs((long)((f - heiltal) * p[precision])); itoa(desimal, a, 10); return ret; } */ // soft reset implementation function void softReset() { asm volatile (" jmp 0"); } |
Wat is een P1 poort? De P1 poort is een seriele poort (is optioneel) op je digitale elektra meter waarin …