kaluma: HTTP Module not working on Raspberry Pi Pico W

Hi there

I’m trying the HTTP module on Raspberry Pi Pico W, but it doesn’t work. There doesn’t seem to be any particular error.

I tried the following code.

const { WiFi } = require('wifi');
const wifi = new WiFi();
const http = require('http');

wifi.scan((err, scanResults) => {
    if (err) {
        console.error(err);
    } else {
        wifi.connect({ ssid: 'SSID', password: 'PASS' }, (err) => {
            if (err) {
                console.error(err);
            } else {
                console.log(`-----Wi-Fi connected-----`);        
                try {
                    http.get({ host: 'hoge.hoge.com', path: '/' }, function (response) {
                        response.on('data', function (chunk) {
                            console.log('received: ', chunk);
                        });
                    });
                } catch (error) {
                    console.log(`---`);
                    console.log(error);
                }
            }
      });
    }
});

It seems that the people commenting in this discussion are having the same issue.

https://github.com/kaluma-project/kaluma/discussions/550

Anyone have any ideas?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 21

Commits related to this issue

Most upvoted comments

@AcousticTypewriter @anubhavgupta I finally found the issue in the http code. please try it with the attached test FW and let me know your test result. kaluma-rp2-pico-w-1.1.0-beta.2_0624_http_get_test.uf2.zip

I tested with this test code. The host in the http header is needed for the “httpbin.org”.

const { WiFi } = require('wifi');
const wifi = new WiFi();
const http = require('http');

wifi.scan((err, scanResults) => {
  if (err) {
      console.error(err);
  } else {
    wifi.connect({ ssid: 'myssid', password: 'mypassword' }, (err) => {
      if (err) {
          console.error(err);
      } else {
          console.log(`-----Wi-Fi connected-----`);
      }
    });
  }
});

const options = {
  host: 'httpbin.org',
  port: 80,
  path: '/get',
  method: 'GET',
  headers: {Host: 'httpbin.org', Accept: 'application/json'}
};

const req = http.request(options, (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
  res.on('data', (chunk) => {
    console.log(`BODY: ${chunk}`);
  });
  res.on('end', () => {
    console.log('No more data in response.');
  });
});

req.on('error', (e) => {
  console.error(`problem with request: ${e.message}`);
});

// Finish the request
req.end();

@anubhavgupta Thank you let me check that point!!!

same result, when i try with ip address.

@anubhavgupta Thanks to your help I found out that current network driver does not support URLs. Let me implement URL feature in the pico-w network driver.