Serial monitor show blank output

I got it to work on my WeMos D1 board with the examples door sensor. Thanks for your details instructions. The serial monitor show output for a while and now the serial monitor quit working and does not show any output. I check the correct com port and speed set to same at the code but still show blank output. I reboot the computer and same code but no output? Anyone know how to fix this?

Hi, @Chen_Tea,

Just as a reminder, you must flash your device and then open up the Serial Monitor. It can’t be open while flashing because the process of flashing uses serial.

Could you close the serial monitor, flash, and open it again? Also, could you send along some screenshots of your desktop while doing so?

Now, I have bigger problem. The connection MQTT to Losant keep broken when I leave it on for a few minutes. I goto the Losant application stated that the connection lost. Do you know why connection to losant keep broken and unable to reconnect automatically. I have to remove power and boot up then it works for a few minutes only. It is frustrating because it does not work as expected.

Hi @Chen_Tea

I’m sorry you are having troubles. We’ve seen this with the Arduino core. To solve this, we are going to port all of our kits to use Mongoose OS.

I’ve had 10x more success having a stable connection with Mongoose OS. If you would like to go that route, we have some example code that you can use here:

For your project, you can read the GPIO of the door sensor in a similar way.

Can you do examples for me with the door sensor using Mongoose OS? On this example, he did not put complete instructions including setup on the workflow on the Losant. This is my first project and very disappointed not able to get a good connection and stay on long enough to get the data.

Thanks,
Chen

So, I have good news. Everything else in the example you saw will still work. I’m referring to this documentation:

The Losant side of everything is still the same. You can follow those full instructions to get a working application.

In those docs, we are using the ESP8266 Arduino Core. We didn’t make that here at Losant. At the time of creation, Arduino was the best option. We have seen the same thing you have with the ESP8266 chip. Since we didn’t create the ESP8266 Arduino Core, we don’t have too much control over that.

Now we have a new recommendation Mongoose OS. In the instructions, instead of using Arduino to flash your device, you will use the Mongoose OS tool chain. The blog post I sent above should give you a pretty good understanding of how that works.

Lastly, we have example code for you to use for Mongoose OS too:

In this code, we are doing something very similar to what you need:

load('api_config.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');
load('api_timer.js');

// Helper C function get_led_gpio_pin() in src/main.c returns built-in LED GPIO
let led = ffi('int get_led_gpio_pin()')();

let getInfo = function() {
    return JSON.stringify({data:{ total_ram: Sys.total_ram(), free_ram: Sys.free_ram() }});
};

// Blink built-in LED every second
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
Timer.set(1000 /* 1 sec */ , true /* repeat */ , function() {
    let value = GPIO.toggle(led);
    print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);

// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
    let topic = '/losant/' + Cfg.get('device.id') + '/state';
    let message = getInfo();
    let ok = MQTT.pub(topic, message, 1);
    print('Published:', ok ? 'yes' : 'no', 'topic:', topic, 'message:', message);
}, null);

Every second we toggle an LED, and when the button on the ESP8266 is pressed, we report state to Losant. You can do something similar for the door sensor. Every second ( or any other interval you want ), you can ready the GPIO of the door sensor and report that to Losant. Just make sure you use the same attribute name.

Also, as I mentioned before, everything on the Losant side will be the same. The only difference is Mongoose OS. You would just have to make some small changes to the code for your use case.

I try to start with new codes and make some changes on Arduino IDE and still got error dropping connection. Here is the Application Log:

Any idea whats going on with Losant or Is my end on the DI board?

Thanks,
chen

The underlying issue is the SSL library used by the Arduino Core for ESP8266. You can read plenty of other issues here:

https://github.com/esp8266/

As a result, we have moved away from using the Arduino Core, which is a community project, and not officially supported by Arduino in any way. We’ve had much more success with MongooseOS.

If you’re not concerned with the data being encrypted between your device and Losant, you can modify the source code we provide with the kit to remove SSL. This will likely result in a more stable connection.

The changes you’ll need to make are:

Line 26
WiFiClientSecure wifiClient;

Change to:
WiFiClient wifiClient;

Line 56
device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

Change to:
device.connect(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

We are working on providing MongooseOS versions of all of our kits to replace the Arduino Core.