Guest User

Untitled

a guest
Feb 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. [AC] WiFi.config(IP=0.0.0.0, Gateway=0.0.0.0, Subnetmask=0.0.0.0,
  2. DNS1=0.0.0.0, DNS2=0.0.0.0) [AC] DHCP client(STARTED)
  3. [AC] WiFi.begin()
  4. [AC] Connecting........[AC] established IP:192.168.1.139
  5. [AC] http server started
  6. Wifi connected: 192.168.1.139
  7. Connected to endpoint
  8. Daily:13.37
  9. Monthly:1111
  10. 4
  11. 13.37
  12. 4
  13. 1111
  14. 4
  15. 13.37
  16. 4
  17. 1111
  18. 4
  19. 13.37
  20. 4
  21. 1111
  22. 4
  23. 13.37
  24. 4
  25. 1111
  26. 2
  27. h
  28. 0
  29.  
  30. 2
  31. h
  32. 0
  33.  
  34. 2
  35. h
  36.  
  37. void fetchJSONandPutValues(){
  38.  
  39. HTTPClient http; //Object of class HTTPClient
  40. http.begin(projectURL);
  41. int httpCode = http.GET();
  42. //Check the returning code
  43. if (httpCode > 0) {
  44. //Parsing
  45. const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
  46. DynamicJsonBuffer jsonBuffer(bufferSize);
  47. JsonObject& root = jsonBuffer.parseObject(http.getString());
  48. // Parameters
  49. daily = root["daily"];
  50. monthly = root["monthly"];
  51. // Output to serial monitor
  52. Serial.print("Daily:");
  53. Serial.println(daily);
  54. Serial.print("Monthly:");
  55. Serial.println(monthly);
  56.  
  57. finalDaily = (char *) daily;
  58. finalMonthly = (char *) monthly;
  59. }
  60.  
  61. http.end(); //Close connection
  62.  
  63. //setLCDValues(daily);
  64. }
  65.  
  66. void setLCDValues(char * value){
  67.  
  68. int charsInValue = strlen(value);
  69. boolean decimalPoint = false;
  70. int numLEDElements = charsInValue;
  71. char cleanedValue[8] ;
  72.  
  73. //look for point position
  74. int positionPoint = 999;
  75.  
  76. for (int i = 0; i < charsInValue; i++){
  77. if (value[i] == '.')
  78. {
  79. positionPoint = i;
  80. numLEDElements -= 1;
  81. break;
  82. }
  83. }
  84.  
  85. int j = 0 ;
  86. for (int i = 0; i < charsInValue; i++){
  87. if (value[i] != '.')
  88. {
  89. cleanedValue[j] = value[i];
  90. j++;
  91. }
  92. }
  93.  
  94. Serial.println(numLEDElements);
  95.  
  96. for (int i = 0; i < numLEDElements; i++){
  97.  
  98. if ( i == positionPoint -1 )
  99. {
  100. ledDisplay.setChar(0, numLEDElements -1 - i, cleanedValue[i], true);
  101. }
  102. else
  103. {
  104. ledDisplay.setChar(0, numLEDElements -1 - i, cleanedValue[i], false);
  105. }
  106. }
  107. }
  108.  
  109. currentMillis = millis();
  110.  
  111. if (currentMillis - previousMillis >= interval){
  112.  
  113. previousMillis = currentMillis;
  114.  
  115. if (showDaily)
  116. {
  117. setLCDValues(finalDaily);
  118. showDaily = false;
  119. Serial.println(daily);
  120. }
  121. else
  122. {
  123. setLCDValues(finalMonthly);
  124. showDaily = true;
  125. Serial.println(monthly);
  126. }
  127. }
Add Comment
Please, Sign In to add comment