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.
 
 
 
 
 

104 lines
1.8 KiB

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