Guest User

Untitled

a guest
Dec 29th, 2013
10
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // caracter codes
  2. #define END_OF_LINE     10       // \n
  3. #define OPEN_BRACKET    "{"
  4. #define CLOSE_BRACKET   "}"
  5.  
  6.  
  7. /***********************************************
  8. sendHbeat
  9. Send a xPL hbeat message
  10. Input : n/a
  11. Output : n/a
  12. ***********************************************/
  13. void sendHbeat() {
  14. Serial.println("Send hbeat message");
  15. char buffer[200];
  16.  
  17. /**** header ****/
  18. printf(buffer, "xpl-stat\n{\n");
  19. printf(buffer, "%shop=1\n", buffer);
  20. printf(buffer, "%ssource=%s\n", buffer, MY_SOURCE);
  21. printf(buffer, "%starget=*\n}\n", buffer);
  22.  
  23. /**** body ****/
  24. printf(buffer, "%shbeat.basic\n{\n", buffer);
  25. printf(buffer, "%sinterval=%i\n", buffer, HBEAT_INTERVAL);
  26. printf(buffer, "%sport=%u\n", buffer, localPort);
  27. printf(buffer, "%sremote-ip=%s\n",buffer, myIPAdress);
  28. printf(buffer, "%s}\n", buffer);
  29. //Serial.println(buffer);
  30.  
  31. /**** Send it ****/
  32. Udp.beginPacket(broadCastIp, xplPort);
  33. Udp.write(buffer);
  34. Udp.endPacket();
  35. }
  36.  
  37. /***********************************************
  38.    sendTeleinfoBasic
  39.    Send a xPL teleinfo basic stat message
  40.    Input : n/a
  41.    Output : n/a
  42. ***********************************************/
  43. void sendTeleinfoBasic() {
  44.     Serial.println("Send Teleinfo stat");
  45.     char buffer[512];
  46.  
  47.     /**** header ****/
  48.     printf(buffer, "xpl-stat\n{\n");
  49.     printf(buffer, "%shop=1\n", buffer);
  50.     printf(buffer, "%ssource=%s\n", buffer, MY_SOURCE);
  51.     printf(buffer, "%starget=*\n}\n", buffer);
  52.  
  53.     /**** body : specification part ****/
  54.     printf(buffer, "%steleinfo.basic\n{\n", buffer);
  55.     /**** body : developper part ***/
  56.     // numéro de série du compteur
  57.     printf(buffer, "%sadco=%s\n", buffer, ADCO);
  58.     // Option tarifaire choisie
  59.     printf(buffer, "%soptarif=%s\n", buffer, OPTARIF);
  60.     // Intensité souscrite,
  61.     printf(buffer, "%sisousc=%i\n", buffer, ISOUSC);
  62.     // Index option Heures Creuses - Heures Creuses
  63.     printf(buffer, "%shchc=%lu\n", buffer, HCHC);
  64.     // Index option Heures Creuses - Heures Pleines
  65.     printf(buffer, "%shchp=%lu\n", buffer, HCHP);
  66.     // Période Tarifaire en cours
  67.     printf(buffer, "%sptec=%s\n", buffer, PTEC);
  68.     // Intensité Instantanée
  69.     printf(buffer, "%siinst=%i\n", buffer, IINST);
  70.     // Intensité maximale appelée
  71.     printf(buffer, "%simax=%i\n", buffer, IMAX);
  72.     // Puissance apparente
  73.     printf(buffer, "%spapp=%i\n", buffer, PAPP);
  74.     // Horaire Heures Pleines Heures Creuses
  75.     printf(buffer, "%shhphc=%s\n", buffer, HHPHC);
  76.     // Mot d'état du compteur
  77.     printf(buffer, "%smotdetat=%s\n", buffer, MOTDETAT);
  78.     printf(buffer, "%sdevice=teleinfo\n", buffer);
  79.     printf(buffer, "%s}\n", buffer);
  80.    
  81.     Serial.println(buffer);  
  82.  
  83.     /**** Send it ****/
  84.     Udp.beginPacket(broadCastIp, xplPort);
  85.     Udp.write(buffer);
  86.     Udp.endPacket();
  87. }
RAW Paste Data