Solar Array and home energy dashboard.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

111 lines
1.9 KiB

  1. socket.onopen = function() {
  2. // connected
  3. }
  4. // Indexes for chart series
  5. consumIdx = 0;
  6. gridIdx = 1;
  7. prodIdx = 2;
  8. var msgNumbs = {
  9. p: "#production",
  10. ng: "#netgrid",
  11. c: "#consumption",
  12. };
  13. function netgridcolor(v) {
  14. if (v <= 0)
  15. return "#00ff00";
  16. else
  17. return "#ff0000";
  18. }
  19. socket.onmessage = function(m) {
  20. var msg = m.data.split(" ");
  21. if (msg[0] in msgNumbs) {
  22. // simple update values
  23. var num = parseFloat(msg[1]);
  24. var targ = $(msgNumbs[msg[0]]);
  25. targ.text(num.toString());
  26. // update color for ng
  27. if (msg[0] == "ng") {
  28. $(".gridpower").css('background', netgridcolor(num));
  29. }
  30. } else if (msg[0] == 'o') {
  31. // received overview data
  32. var data = JSON.parse(msg[1]);
  33. console.log(solarchart);
  34. solarchart.navigator.series[consumIdx].setData(data.consumption, false);
  35. solarchart.navigator.series[gridIdx].setData(data.grid, false);
  36. solarchart.navigator.series[prodIdx].setData(data.production, false);
  37. solarchart.redraw();
  38. }
  39. }
  40. var solarchart = Highcharts.stockChart('solarchart', {
  41. chart: {
  42. type: 'area',
  43. zoomType: 'x'
  44. },
  45. title: {
  46. text: 'Panel Production'
  47. },
  48. subtitle: {
  49. text: document.ontouchstart === undefined ?
  50. 'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
  51. },
  52. navigator: {
  53. adaptToUpdatedData: false, // XXX - keep?
  54. series: [
  55. {
  56. name: 'consumptionNav',
  57. showInNavigator: true,
  58. data: [],
  59. },
  60. {
  61. name: 'gridNav',
  62. showInNavigator: true,
  63. data: [],
  64. },
  65. {
  66. name: 'productionNav',
  67. showInNavigator: true,
  68. data: [],
  69. },
  70. ]
  71. },
  72. xAxis: {
  73. type: "datetime",
  74. title: {
  75. enabled: false
  76. }
  77. },
  78. yAxis: {
  79. title: {
  80. text: 'kW'
  81. }
  82. },
  83. tooltip: {
  84. split: true,
  85. valueSuffix: ' kW'
  86. },
  87. plotOptions: {
  88. area: {
  89. stacking: 'normal',
  90. lineColor: '#666666',
  91. lineWidth: 1,
  92. marker: {
  93. lineWidth: 1,
  94. lineColor: '#666666'
  95. }
  96. }
  97. },
  98. series: [
  99. {
  100. name: 'grid',
  101. data: fakeData,
  102. },
  103. ]
  104. });