Tracking an E-bike and reading through A0 it's battery level

Hello!

I’m a newby and already got the GPS working to give me the location of my e-bike every 30 seconds. Now I wanted to add the reading of it’s battery level through an analog read, but I’m getting this error: “invalid conversion from ‘int32_t {aka long int}’ to ‘const char*’ [-fpermissive]”. Any help please?

Here’s the code:

#include <AssetTrackerRK.h>

#include "AssetTrackerRK.h"

int transmittingData = 1;

long lastPublish = 0;

int delaySeconds = 30;

const int BikeBattRead = A0;

AssetTracker t = AssetTracker();

FuelGauge fuel;

void setup() {
    
    t.begin();
    
    pinMode(BikeBattRead, INPUT);
    
    t.gpsOn();
    
    Serial.begin(9600);
    
    Particle.function("tmode", transmitMode);
    Particle.function("LiPo", LiPoStatus);
    Particle.function("gps", gpsPublish);
    Particle.function("BikeBatt", BBPublish);
    Particle.keepAlive(30);
}


void loop() {
    
    t.updateGPS();
   
    if(millis()-lastPublish > delaySeconds*1000){
        
        lastPublish = millis();
        
        Particle.publish("BB", analogRead(BikeBattRead), 60, PRIVATE);
        
        Serial.println(t.preNMEA());
        
        if(t.gpsFix()){

            if(transmittingData){

                Particle.publish("G", t.readLatLon(), 60, PRIVATE);
            }
            
            Serial.println(t.readLatLon());
         
        }
        
    }

}

int transmitMode(String command){
    transmittingData = atoi(command);
    return 1;
}

int gpsPublish(String command){
    if(t.gpsFix()){ 
        Particle.publish("G", t.readLatLon(), 60, PRIVATE);

        return 1;
    }
    else { return 0; }
}

int LiPoStatus(String command){

    Particle.publish("L", 
          "v:" + String::format("%.2f",fuel.getVCell()) + 
          ",c:" + String::format("%.2f",fuel.getSoC()),
          60, PRIVATE
    );

    if(fuel.getSoC()>10){ return 1;} 

    else { return 0;}
    
}
    
int BBPublish(String command){

    Particle.publish("BB", 
    
    analogRead(BikeBattRead), 60, PRIVATE);

}

It’s right in the “analogRead(BikeBattRead)” commands that I get the error.

Please help me out.

The error indicates that the data conversion is not going as smooth as it should. Take a look at the docs on what kind of arguments are accepted in publishes.

2 Likes

Thanks! I already took a dive on the docs but can’t find the right way to put it… I found this examples:

// SYNTAX
Particle.publish(const char *eventName, const char *data, int ttl, PRIVATE);
Particle.publish(String eventName, String data, int ttl, PRIVATE);

// EXAMPLE USAGE
Particle.publish("front-door-unlocked", NULL, 60, PRIVATE);

Which I believe I’m doing correct, right?

int bbPublish(String command){
    
    Particle.publish("BB", voltage, 60, PRIVATE);

}

Could you please give me an example of how to do it properly?

Already solved it, I get 2051 in the reading, I believe i have to adjust the formula now.

Thanks anyway

Just for the record here: publish takes a char array as its second argument, not a numeric type.

3 Likes

And your int bbPublish(String) promises to return an integer value, but your code does not.

2 Likes