ChipChop Support Forum
Log in
Log out
Join the forum
My Details
REPLIES: 8
VIEWS: 101
BACK
REPLY TO THIS POST
SebyLT
29 Nov 2024
Analog reading sending problem

Hi, I can't see the analog reading value (A0) on the platform.
Can anyone tell me where I'm going wrong?
Thank you.



#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif

#define CHIPCHOP_DEBUG true //set to false for production

#include "src/ChipChop_Config.h"
#include "src/ChipChopEngine.h"
extern ChipChopEngine ChipChop;
//Plugins included: ChipChop Engine,Keep Alive,WiFi Portal,Preferences Manager,OTA (Over the air updates),
#include "src/ChipChopPlugins.h"
extern ChipChopPluginsManager ChipChopPlugins;
#include "src/ChipChop_Includes.h"

#include <SimpleTimer.h>
SimpleTimer timer;

//******************** connection credentials can be found in the device settings ********************
String server_uri = "wss://api1.chipchop.io/wsdev/";
String uuid = "ChpChp**x0366b******029a72b";
String auth_code = "e37558bf7d4c4*******cdd";
String device_id = "testacq";
//******************** connection credentials can be found in the device settings ********************

int livello ;

void ChipChop_onCommandReceived(String target_component,String command_value, String command_source, int command_age){
Serial.println(target_component);
Serial.println(command_value);
// If you are using the AutoMode plugin, just handle here components that are not managed by AutoMode
}

void setup(){

Serial.begin(9600);
delay(1000);
timer.setInterval(1000L, myTimerEvent);

//WifiPortal.ssid("", "");// Optional: set default WiFi Portal ssid & password <br>or remove this line and use your phone to set the WiFi portal
//basic ChipChop engine settings, all others are in the ChipChop_config.h ////
ChipChop.debug(true); //set to false for production
ChipChop.commandCallback(ChipChop_onCommandReceived);
ChipChop.start(server_uri, uuid, device_id, auth_code);
ChipChopPlugins.start();//Start all plugins
ChipChop.updateStatus("livello",livello);// set here the initial status for all components that are not handled by the AutoMode plugin
}


void myTimerEvent(){
livello = analogRead (A0);// acquisisce il segnale del sensore
ChipChop.updateStatus("livello",livello);
}


void loop(){
//keep the ChipChop engine and plugins running
ChipChop.run();
ChipChopPlugins.run();
}





Attached images
Gizmo
29 Nov 2024

Hi Seby,

The code looks good so I hope I understand your question correctly and you just want to see the live status of your device?

Option 1

Menu on the left in the Dev Console > "Live Control" will show you the live status, just click on your device in the list
(It looks like you have your browser translating the menu so it's option 7)

Option 2

    1. On your phone go to https://my.chipchop.io (make sure it's https://)
    2. Android - top menu > 3 vertical dots > add to home screen
     iPhone - bottom menu > share > add to home screen
    3. close the browser and find the app on your phone and start it from there
    4. log in with same credentials as for the Dev Console

You can now view and control your device from anywhere

Let me know if that's what you are looking for or it's something else

G
SebyLT
29 Nov 2024

Hi Gizmo, yes unfortunately in "Real time control" the status remains with a value of "0", in reality the sensor is connected to port A0 and should give me a value of around 170-180.


Attached images
Gizmo
29 Nov 2024

What do you get when you output to serial monitor?




void myTimerEvent(){
    livello = analogRead (A0);// acquisisce il segnale del sensore

    Serial.println(livello); //<<< what do you see in the serial monitor

    ChipChop.updateStatus("livello",livello);
}




SebyLT
29 Nov 2024


in " void myTimerEvent() " I added a Serial.print ("LIVELLO : "); Serial.println (livello);

but it is not shown on the serial line, perhaps the problem concerns the timer?


Attached images
Gizmo
29 Nov 2024

Yeah, screw the timer lib, just do it the old fashioned way




unsigned long timeout = 0;

void myTimerEvent(){
    livello = analogRead (A0);// acquisisce il segnale del sensore
    
    Serial.print("A0 = ");
    Serial.println(livello);

    ChipChop.updateStatus("livello",livello);
}


void loop(){
    //keep the ChipChop engine and plugins running
    ChipChop.run();
    ChipChopPlugins.run();
    
    if(millis() - timeout >= 1000){

        myTimerEvent();
        timeout = millis();

    }
    
}



Keep touching the A0 pin to see if the values change
Gizmo
29 Nov 2024

Ah...hold on, you should also declare A0 as input




void setup(){
        
    pinMode(A0, INPUT);

}



SebyLT
29 Nov 2024

It was the timer........

It works now :)

Thank you !
Gizmo
29 Nov 2024

😀