Jump to content
⚠️ Deprecation Notice: Cloud Control API V1 – Switch to V2 ×

Script not working with new firmware 20240822-121046/1.4.3-g143ff62


Recommended Posts

Posted

I get error regularly after updating the firmware executing an old running script at

in function called from system08:59:18

Uncaught Error: Too many calls in progress08:59:19

at });08:59:19

^



Script:
 

let variables = {
  collectionInterval: 2000, // Time in milliseconds between data collections
  sendInterval: 2000, // Time in milliseconds to send data in bulk
  mqttTopic: 'abc',
  hardwareId: '08F9E0E627FC',
  dataBuffer: [], // Buffer to store device status data
  enableA: true,  // Flag to enable/disable collection for device A (id: 0)
  enableB: true   // Flag to enable/disable collection for device B (id: 1)
};

function getDeviceStatus() {
  let commonData = {
    ts: new Date().toISOString()
  };
  let collectedA = !variables.enableA;  // Assume collected if A is disabled
  let collectedB = !variables.enableB;  // Assume collected if B is disabled
  
  function checkAndPush() {
    if (collectedA && collectedB) {
      if (variables.enableA) {
        var dataEntryA = Object.assign({}, commonData, deviceData[0]);
        variables.dataBuffer.push(dataEntryA);
      }
      if (variables.enableB) {
        var dataEntryB = Object.assign({}, commonData, deviceData[1]);
        variables.dataBuffer.push(dataEntryB);
      }
      publishBulkToMQTT(); // Push data to MQTT once both devices are processed
    }
  }

  let deviceData = [];

  if (variables.enableA) {
    Shelly.call("EM1.GetStatus", {"id": 0}, function(responseA) {
      if (responseA) {
        Shelly.call("EM1Data.GetStatus", {"id": 0}, function(responseEmDataA) {
          if (responseEmDataA) {
            responseA['emd'] = responseEmDataA;
          }
          deviceData[0] = responseA;
          collectedA = true;
          checkAndPush();
        });
      } else {
        collectedA = true; // Mark A as processed even if no data
        checkAndPush();
      }
    });
  }

  if (variables.enableB) {
    Shelly.call("EM1.GetStatus", {"id": 1}, function(responseB) {
      if (responseB) {
        Shelly.call("EM1Data.GetStatus", {"id": 1}, function(responseEmDataB) {
          if (responseEmDataB) {
            responseB['emd'] = responseEmDataB;
          }
          deviceData[1] = responseB;
          collectedB = true;
          checkAndPush();
        });
      } else {
        collectedB = true; // Mark B as processed even if no data
        checkAndPush();
      }
    });
  }

  if (!variables.enableA && !variables.enableB) {
    return;
  }
}

function publishBulkToMQTT() {
  if(variables.dataBuffer.length > 0){
    let mqttData = {
      name: variables.hardwareId,
      type: 'powerpro',
      data: variables.dataBuffer
    };
    MQTT.publish(variables.mqttTopic, JSON.stringify(mqttData));
    variables.dataBuffer = []; // Clear the buffer after sending
  }
}

Timer.set(variables.collectionInterval, true, getDeviceStatus);
Timer.set(variables.sendInterval, true, publishBulkToMQTT);

  • 2 weeks later...
Posted

I already had this kind of error in the past (with different firmware).

It could be if you make too many Shelly.Call in a row. But this is not the case here because you wait for a call to complete before making a new one. In other words, the next call is embedded in the return function of the first one.

I finally happened to find that : copy the entire script content, delete the script, create new empty script (can be with same name), paste the script content, save the script, made the trick, could run the script with no more error.

Don't ask me why !?!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...